now this function is public wich will reseve a parameter from the user..
i thought that i should creat the node and then i can gust link it to the
tree...!!thats way i call the predefined insert wich takes as parameter
a pointer to the node..and i put it in the private of my class...
this is the code..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
void insert<Type>(TreeNode<Type>*& current)
{
if (root==NULL)
root=current;
TreeNode<Type>* Nroot=root;
if (count%2==0)//contain the number of nodes
{
Nroot->leftLink=current;
Nroot=Nroot->rightLink;
}
else
Nroot->left=current;
}
its not realy perfect put this what i came up so that i can blance my tree
and i want to combine the 2 algorithms but i didnt go so far..
please may any one hlep me..thanks indeed
The first function isn't doing anything that TreeNode constructor should be doing. That is to say, TreeNode constructor should take data as the parameter, and then assign the data value, and set the links to NULL, and in this case, increment a class static counter.
The second function uses the count in a bizarre way. If you want to check if the nodes point to another node, you should compare their values with NULL, not against the TreeNode count.
im very sorry i was confused i want to connect the last code with the above
the above i did to calculate the number of nodes in the tree and decide which
should subtree we should start with...in other words i didnt figure out how
can i balnce the tree while i have an input...
if you may help me.