Thread: how can I read in a binary tree from a file and prints out on screen

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    1

    how can I read in a binary tree from a file and prints out on screen

    struct treenode {
    int data;
    struct treenode * left;
    struct treenode * right;
    }
    typedef struct treenode *btree;
    Your program will require a command line argument which is the name of the input file that
    holds the nodes and structure of the binary tree. (The details of the input file is given below).
    Note that your program will construct the requested binary tree from scratch by using the
    given structure; and it will not request any data from the user (except the filename which is a
    command line argument). The output of your program will be:
    1. The Size of the Tree: . . .
    2. The Height of the Tree: . . .
    3. Number of Leaf Nodes: . . .
    4. Sum of all Nodes: . . .
    5. Sum of Internal Nodes: . . .
    6. Sum of Leaf Nodes: . . .
    7. Preorder Traversal of Tree: . . .
    8. Minimum & Maximum Numbers in Tree: . . .
    9. Is a BST (0/1): . . .
    Note that you are required to implement each entry with a separate recursive function. You
    are not allowed to get these information while processing the data from the file. You will first
    construct the binary tree from the file; then call the corresponding recursive functions for
    each case.
    There will be at least 9 recursive functions which will be based on following prototypes.
    int size (btree mytree);
    int height (btree mytree);
    int num_leaves (btree mytree);
    int sum_all_nodes (btree mytree);
    int sum_internal_nodes (btree mytree);
    int sum_leaf_nodes (btree mytree);
    void preorder (btree mytree);
    int min_max (btree mytree, int *min, int * max);
    int Is_BST (btree mytree)
    Last edited by kissland; 04-26-2008 at 07:24 PM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Who knows? Answer: the person who decided what format your data file is in.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  2. Search Engine - Binary Search Tree
    By Gecko2099 in forum C Programming
    Replies: 9
    Last Post: 04-17-2005, 02:56 PM
  3. Binary Tree, couple questions
    By scoobasean in forum C Programming
    Replies: 3
    Last Post: 03-12-2005, 09:09 PM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  5. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 10:45 PM