473,408 Members | 1,786 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,408 software developers and data experts.

print all the between values of a tree

momotaro
357 100+
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?

Expand|Select|Wrap|Line Numbers
  1. void PrintRange(TreeNode *root, KeyType KeyMin, KeyType KeyMax){
  2. if (!root)
  3.     return;
  4. else{
  5.     if (root->entry > KeyMin)
  6.         PrintRange(root->left, KeyMin, KeyMax);
  7.     if (root->entry >= KeyMin && root->etry <= KeyMax)
  8.         printf("%d", root->entry);
  9.     if (root->entry < KeyMax)
  10.         PrintRange(root->right, KeyMin, KeyMax);
  11.     }
  12. }
Apr 28 '07 #1
1 1327
huan
12
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?

Expand|Select|Wrap|Line Numbers
  1. void PrintRange(TreeNode *root, KeyType KeyMin, KeyType KeyMax){
  2. if (!root)
  3.     return;
  4. else{
  5.     if (root->entry > KeyMin)
  6.         PrintRange(root->left, KeyMin, KeyMax);
  7.     if (root->entry >= KeyMin && root->etry <= KeyMax)
  8.         printf("%d", root->entry);
  9.     if (root->entry < KeyMax)
  10.         PrintRange(root->right, KeyMin, KeyMax);
  11.     }
  12. }
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?
Apr 29 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

23
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...
4
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....
2
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. ...
4
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...
23
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...
4
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
3
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...
1
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...
8
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...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
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,...
0
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...
0
jinu1996
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...
0
tracyyun
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...
0
agi2029
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,...
0
isladogs
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...
0
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...

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.