473,385 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 1802

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Don Bruder | last post by:
A week or two ago, I asked here about porting Python to C. Got some good answers (Note 1) but now I've got another question. Actually, more a request for clarification of a topic that both the...
4
by: Tarique Jawed | last post by:
Alright I needed some help regarding a removal of a binary search tree. Yes its for a class, and yes I have tried working on it on my own, so no patronizing please. I have most of the code working,...
1
by: sugaray | last post by:
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
9
by: Steven | last post by:
Hello, I have a question about strcmp(). I have four words, who need to be compared if it were two strings. I tried adding the comparison values like '(strcmp(w1, w2) + strcmp(w3, w4))', where...
4
by: Today's Mulan | last post by:
I guess this is new, at least to people who don't know about this, like me, please be prepared to give me a satifying answer, so please tell me how the compiler "knows" variable "i" as in a...
27
by: Chad | last post by:
The problem is: Write a recursive version of the function reverse(s), which reverses the string s in place. In "The C Answer Book", Second Edition, near the bottom of page 95, the authors say...
90
by: John Salerno | last post by:
I'm a little confused. Why doesn't s evaluate to True in the first part, but it does in the second? Is the first statement something different? False print 'hi' hi Thanks.
1
by: hn.ft.pris | last post by:
I have the following code: Tree.h defines a simple binary search tree node structure ########## FILE Tree.h ################ #ifndef TREE_H #define TREE_H //using namespace std; template...
7
by: Vinodh | last post by:
Started reading about Binary Trees and got the following questions in mind. Please help. Definition of a Binary Tree from "Data Structures using C and C++ by Tanenbaum" goes like this, "A...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.