Suppose that we represent a binary tree using link structures. The node structure is
typedef struct node {
char label[5];
int descendands
struct node *lchild, *rchild
} NODE;
Write a function that traverses the tree and initializes the member descendands when a node is visited. The value of descendands of a node is the number of descendants of the node. Write a program that tests the function. The function should be tested for three different trees, one tree should be empty, another should be just a list of length 5, the third one should be a tree of 7 nodes and 4 leafs.
Any answers/hints are welcome
Structures - C language?
You can visit my blog
http://codesbyshariq.blogspot.com for programs and code in C, C++, C#, Java, VB abd solutuions of the problems related to computers.
I have some programs related to DS so you can get hint from them.
Reply:Hint 1: You forgot to say whether you want pre-order, in-order, or post-order traversal. :)
Hint 2: Recursion is your friend. At any given node, desendants is equal to the sum of descendants of each child.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment