Any particulary reason you're writing procedural code in C++? A better approach would be to create a tree class that handles everything.
Anyways, one major problem you have is that you pass a single pointer to traverse. The pointer in traverse is local to the function, so setting
current = new node;
Only modifies the pointer in the function.
Have you been reading a tutorial on binary trees? If you have, I think you should re-read it, and possibly find one that is specifically object oriented.
GloriousEremite
Junior Poster in Training
65 posts since Jul 2006
Reputation Points: 108
Solved Threads: 14
For a full blown implementation of Binary trees in OO C++ see here:
http://library.thinkquest.org/C005618/text/binarytrees.htm
A good way of approaching the problem will be to jot down all the details (like variables, class design, usage etc) which though may seem as a waste of time to you will definately help you in the long run. IF this kind of documentation is made, the coding just becomes mechanical.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734