It is a simple programme to make a list of numbers. I'm using a class numbers, and a class for the list. The problem is root changes whenever i add another element. (tree is the name of my list class)
void tree::add(number *num)
{
if (root == NULL) { // empty tree
root = num;
return;
}
number *curr = root;
cout << "ROOT CHANGED TO : " << root->num << endl;
number *prev; // find insertion point
while (curr!=NULL) { // find a correct leaf to insert at
prev = curr;
if (num->num > curr->num) {
curr = curr->right;
cout << "NUM " << num->num <<endl;}