Thread: Binary tree

  1. #1
    Registered User
    Join Date
    Dec 2018
    Posts
    4

    Binary tree

    How would you print the biggest N numbers from big to small in a binary tree without put it in an array?

  2. #2
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    if you created your tree in-order, left to right, then traverse it in-order, right to left...

  3. #3
    Registered User
    Join Date
    Dec 2018
    Posts
    4
    I know how to print All values but i don't know how to print N values.

  4. #4
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    Come on! How difficult is to change this (assuming you are traversing a binary three recursively):
    Code:
    void traverse(node_T *rootp)
    {
      if ( rootp )
      {
        traverse( rootp->right );
        visit( rootp );
        traverse( rootp->left );
      }
    }
    To count how many "visits" you did?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Converting From Binary Tree to Threaded Binary Trees
    By elton_fan in forum C Programming
    Replies: 15
    Last Post: 11-08-2007, 11:41 PM
  2. Replies: 2
    Last Post: 08-01-2007, 01:08 PM
  3. Replies: 0
    Last Post: 11-04-2006, 11:07 AM
  4. display tree data in binary tree format
    By xddxogm3 in forum C++ Programming
    Replies: 4
    Last Post: 12-11-2003, 12:47 AM
  5. b-tree (not binary tree) implementation help
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 01-02-2002, 03:30 PM

Tags for this Thread