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

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)

2. Who knows? Answer: the person who decided what format your data file is in.