954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Binary Search Trees - Need Help Indicating Node Level

Hey guys. I have a project due in 2 weeks, so I have a little bit of time - but I have a lot of work to do, so I want to get this finished. I'm taking a C++ Data Structures class at my high school.. and we have a project that I am stuck on.

It's using Binary Search Trees. I need to input 10 values into the tree, do traversals through the tree (inorder, preorder, and postorder) then indicate which level each node is on. I got all of the traversals down, i can indicate how many leaf nodes there are, nodes with 1 children, and nodes with 2 children - however I don't know what how to figure out the level. I'm new to programming in C++, so this may be an easy question that I should be able to figure out. I'm guessing that I should initialize level to -1 (since the level would be base 0), then increment it every time a node is inserted. The thing is, there can be more than one node on each level, so I'm a little confused. Can anyone help? I just need a little hint to get me started.

Thanks so much.

ardeth32
Newbie Poster
1 post since May 2008
Reputation Points: 10
Solved Threads: 0
 
vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You