Hmm...I haven't done trees yet, but there are a couple of things that come to mind:

(1) "back" is undeclared. Unless this is some sort of global variable...(bad idea anyway)

(2) You attempt to point a type POINT_NODE to a type TREE. Are they really compatible?

05-06-2002

Ted

It seems that the first node is the only node in your tree.
You don't seem to be moving any pointers.
Try not to batch process your tree. insert yor nodes one at a time.
You need to first write out your pseudo code. Some thing like:

// search for insertion point
while current != to NULL
if key == current->key
return duplicate_key
move parent instep with current
compare if key < current->key
current = current->left
else current = current->right
end while

BTW: I just wanted to point out to "teedee" that although not a big "no-no", this thread belongs on the C board.

05-06-2002

teedee46

Thanks for everyone's help. I actually have it working now after hours and hours of work.

Why does this belong on the c board?

05-06-2002

Ted

Your add_node() and your buildTree() logic is out of whack.

Follow my psuedo code. Normally your inout data will be read
from a file or from the keyboard. Call insertNode( treeType *,
keyType ) from main or a getKeyInput(). Pass the root pointer
and the key value to insertNode(). Normally, you don't move the
root pointer, there for:

Code:

current = root;

Next, we must search for the insertion point, this continues until
current points to NULL. If the tree is empty, the root is NULL
Else keep moving current until it points to a NULL child pointer

// search for insertion point
while current // while the root or current are not NULL

Usually we don't want duplicate keys, so you need a means to deal with them
if key == current->key
return duplicate_key // an enum

Because typically, if this were implemented with C++, there would be no functions taking the "parent" pointer as arguments (except in special cases) because it is usually the "parent" calling the function.:

instead of calling build_tree like traditional C, such as:

TREE t;
LIST_I data;
int size;

build_tree(size, data, &t) ;

It would look more like:

TREE t;
LIST_I data;
int size;

t.build_tree(size, data) ;

Later in the program, you could call functions with "t" taking no parameters since the data could be referenced internally.

For instance, "size" and "data" could become "unofficial" members using a special set of member functions: