January 22nd, 2013, 03:56 PM
Join Date: Nov 2012
Time spent in forums: 5 h 19 m 31 sec
Reputation Power: 0
How to search a tree(postorder) in C
I write a function to search a tree, and find out the node suitable and store them in an array. It is in postorder.
void search_for_node(node *root, node *list) // root is the top of a tree, and the array list is used to store the node that is suitable and the space is enough
if (root == NULL)
for(j=0; j<root->num_children; j++) //num_children is a member of node structure indicating the number of children
if (root->type == ID)
list[num_for++] = root; //num_for is a global variable counting the number of nodes suitable
But it can't work. Is there anything wrong in my code?
Thanks in advance!