help with avl tree

i have a problem with find_imbalance_node.
it did not show balance factor.
it shows only data i don't know why
first,i write it correctly and works correctly
but after a small change in it,it breaks down
please,help me
here is function code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
node * BST::find_imbalance_node(int item)
{
bool found=false;
// node *empty_node=root;
node *locptr=root;
while(!found && locptr!= NULL)
{
if(item<locptr->data){
// if(locptr->left->balance_factor==2||locptr->left->balance_factor==-2)
// empty_node=locptr;
locptr=locptr->left;
}
else if(item>locptr->data){
// if(locptr->right->balance_factor==2||locptr->right->balance_factor==-2)
// empty_node=locptr;
locptr=locptr->right;
}
else
found=true;
}
// if(empty_node==root)empty_node=NULL;

return locptr;
}



like that
1
2
3
4
5
6
7
8
9
10
11
12
13
BST obj;
	obj.insert(30);
	obj.insert(20);
obj.insert(15);
obj.insert(21);
obj.insert(40);
obj.insert(35);
obj.insert(50);
obj.insert(60);
obj.insert(70);

cout<<" i = "<<obj.find_imbalance_node(40)->balance_factor<<endl;
cout<<" i = "<<obj.find_imbalance_node(40)->data<<endl;


it shows :
data=40;
but did not show balance factor.
Last edited on
Topic archived. No new replies allowed.