our teacher gave as this function that normaly should print all the between values of a tree given two values min and max but i dont get it right whene appliying the agorithm of this function on a binary search tree...what is wrong? - void PrintRange(TreeNode *root, KeyType KeyMin, KeyType KeyMax){
-
if (!root)
-
return;
-
else{
-
if (root->entry > KeyMin)
-
PrintRange(root->left, KeyMin, KeyMax);
-
if (root->entry >= KeyMin && root->etry <= KeyMax)
-
printf("%d", root->entry);
-
if (root->entry < KeyMax)
-
PrintRange(root->right, KeyMin, KeyMax);
-
}
-
}
1 1327
our teacher gave as this function that normaly should print all the between values of a tree given two values min and max but i dont get it right whene appliying the agorithm of this function on a binary search tree...what is wrong? - void PrintRange(TreeNode *root, KeyType KeyMin, KeyType KeyMax){
-
if (!root)
-
return;
-
else{
-
if (root->entry > KeyMin)
-
PrintRange(root->left, KeyMin, KeyMax);
-
if (root->entry >= KeyMin && root->etry <= KeyMax)
-
printf("%d", root->entry);
-
if (root->entry < KeyMax)
-
PrintRange(root->right, KeyMin, KeyMax);
-
}
-
}
are those codes copied or you typed again?
In the second if expression , "etry" should be "entry".
If I didn't misunderstand your purpose.
I think you should keep printing their leaves all.
Not just root->entry, you have to go on.
Am I right?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: stewart.midwinter |
last post by:
No doubt I've overlooked something obvious, but here goes:
Let's say I assign a value to a var, e.g.:
myPlace = 'right here'
myTime = 'right now'
Now let's say I want to print out the two...
|
by: Jean-Christophe Michel |
last post by:
Hi,
In a complex merging of two (non ordered) xml files
i need to keep track of the elements of the second tree that were already
merged with first tree, to copy only unused elements at the end....
|
by: TheMax |
last post by:
Hi,
(excuse me for some errors in my english)
I need to print a Tree View control, is it possibile? I search with google,
both in newsgroup and web, but i have not find a solution until now.
...
|
by: Larry Grady |
last post by:
Anyone up for a challenge?
I've been struggling with this for a few days and was hoping someone could
help me. Pouring through all the messageboards I just can't find the
solution.
We have a...
|
by: Antoon Pardon |
last post by:
Now slices are objects in python, I was wondering if slice
notation will be usable outside subscribtion in the future.
Will it ever be possible to write things like:
a = 4:9
for key, value in...
|
by: Anthony Liu |
last post by:
There are many ways to represent a binary tree on an
ascii screen.
1
/ \
2 3
/ \ / \
4 5 6 7
or
|
by: James J. Besemer |
last post by:
I would like to champion a proposed enhancement to Python. I describe the
basic idea below, in order to gage community interest. Right now, it's only
an idea, and I'm sure there's room for...
|
by: quirdan |
last post by:
Hi,
I am after some advice about which data structures I should use. I'm developing a program and I am at the point where all the strings are being generated and printed one by one with...
|
by: slizorn |
last post by:
Hi guys,
I have this coding that I wanted to try out.
Basically this is meant to be done in Java as practice for the Topic trees in data structures and algorithms.
I have recently learned C++ on...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |