![]() |
|
#1
|
|||
|
|||
Binary Search Tree in C++hi guys,
I am having trouble with a binary search tree. I have a .h and .cc file for my binary search tree. and then i have a test file that takes a key, value pair from the user and inserts them into the tree by key. I figured out how to make methods to find keys remove keys and everything else, i am just struggling with how to create a tree in my test file and how the insert method should work. I thought i had it working but it seems its not. Any hints or suggestions would be greatly appreciated. Thank you |
|||
|
#2
|
|||
|
|||
Re: Binary Search Tree in C++First I take out my magic wand and read your mind...Then you post the code you have and your specific problems and questions. Then, and only then, can we help.
|
|
#3
|
|||
|
|||
Re: Binary Search Tree in C++search like you normally do down the tree..........and the first spot of null..........insert the new node there. like ubergeek above said............post your code.
|
|
#4
|
|||
|
|||
Re: Binary Search Tree in C++insert function from BSTDictionary.cc
CPP / C++ / C Code:
BSTDictionary.h CPP / C++ / C Code:
As you can see its just a simple insert method into a binary search tree(recursive). it works ok for the first 2 elements, can distinguish weather to put them on the right or left of the root, but after that it only compares down to the first level, and then just inserts it. i can not figure out what i did wrong to cause it to do that. any hints or help would be greatly appreciated, because i am very very confused. Thanks all. Last edited by cable_guy_67 : 02-Apr-2006 at 12:03.
Reason: Please enclose c++ code in [c++] ... [/c++] tags
|
|
#5
|
|||
|
|||
Re: Binary Search Tree in C++i understand what is wrong with it. lets say you insert 6 2 100 9 4 in that order, it will make 6 the root, then put 2 on its left. Then compare 2 and 100 and put 100 on 2s right and then compare 100 and 9 etc. I just am not sure how to get it to stick to the original tree, it seems like ive tried everything..
|
|
#6
|
|||
|
|||
Re: Binary Search Tree in C++from testing and looking at it.. it seems like there might be something wrong with the way i define Kid in my header file.. but i am real confused to what it is wrong with it...
|
Recent GIDBlog
Accepted for Ph.D. program by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Binary Search Tree.. | triples1488 | C++ Forum | 7 | 21-Mar-2006 08:16 |
| Linear Search | eccoflame | C Programming Language | 3 | 19-Apr-2005 09:36 |
| printing binary search tree | nkhambal | C Programming Language | 2 | 26-Mar-2005 04:01 |
| Please help! Dynamic binary tree problem | robsmith | C Programming Language | 3 | 15-Mar-2005 22:20 |
| Search Engine Positioning 101 and 201 "How To" Tips... | 000 | Search Engine Optimization Forum | 0 | 29-May-2003 11:34 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The