468,792 Members | 1,779 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,792 developers. It's quick & easy.

Question on binary tree

1
/ \
2 3
/ / \
4 5 6
\ / \
7 8 9

Given the binary trees above, determine the order in which the
nodes will be visited in the mixed order given by invoking
function A:

typedef struct treenode TreeNode;
typedef struct treenode {
TreeNode *left;
int entry;
TreeNode *right;
}TreeNode;

void A(TreeNode *root)
{
if(root) {
printf("%d\n",root->entry);
B(root->left,Visit);
B(root->right,Visit);
}
}

void B(TreeNode *root)
{
if(root) {
A(root->left,Visit);
printf("%d\n",root->entry);
A(root->right,Visit);
}
}
Nov 14 '05 #1
1 1653

"sugaray" <ru****@sohu.com> wrote in message

Given the binary trees above, determine the order in which the
nodes will be visited in the mixed order given by invoking
function A:

Hi. Unfortunately we're not a homework-doing service.

Personally I find code very difficult to dry-run, so what I suggest you do
is write some code to read in a binary tree (and draw it, to test you have
got the tree correct), and then just call the function on the root of the
tree and see what the output is.

One way to specify a tree is to define a text format

name, parentsname, left

To add a node, search the whole tree until you find the parent. (This is
really wasteful, but easy, and Ok unless the tree is huge).
Nov 14 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Tarique Jawed | last post: by
1 post views Thread by sugaray | last post: by
4 posts views Thread by Today's Mulan | last post: by
90 posts views Thread by John Salerno | last post: by
7 posts views Thread by Vinodh | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.