does anyone have now any good websites that have a page devoted to balancing an unbalanced tree, i found one myself but its in c++ only and i cant find any others.
also if anyone has any advice, (dont want the code), that would be just as good
heres what i think i should do
1) put the node pointers into an array
2) sort the array
3) destroy the root of the tree
4) find the middle of the array
5) do some recursion and keep finding the middle until all the remaining pointers are added to the new tree
when i tried to read the addresses in they sorted themselves, but not the information contained within the addresses, i used an in order traversal
my information is all characters so i want the lowest letters at the start of the array
heres what i got so far (not much i'm afraid)
void balanceTree(PTRnode* &root, datatype &data, int &numberCDS)
{
PTRnode *tempnode[300]; //temporary storage for node addresses
static int index = 0;
tempnode[index]=inOrderTraversal(root, data); //call to function that sorts in Order
index++; //increment index by 1
}
PTRnode* inOrderTraversal(PTRnode* &root, datatype &data)
{
if(root->left!=NULL) //check if root->left is not equal to NULL
{
inOrderTraversal(root->left, data); //call function and go left
}
else
{
return root; //return the roots contents
}
if(root->right!=NULL) //check if root->right is not equal to NULL
{
inOrderTraversal(root->right, data); //call function and go right
}
}
i hope you can make sense out of all that