Thread: Heap Tree
View Single Post
Old 04-28-2005, 12:13 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
The value you're adding will determain where in teh tree it is going to be located, your seach tree here will always have values less than (or equal to) your value to add placed on the left branch, values higher placed on the right.

So some sort of bubble sort algorithm would do, see if the leaf value is less or equal to, then go right, if higher go left, when leaf holds an empty branch in the intended direction, place value here.

The real problem arises when deleting from the tree, then you'd need a balance function to make sure the tree structurial will allways support your adding scheme.

But most likely this tree handling, beeing adding, deleting or balancing will require some form of recursive calling.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote