Remove from Binary search tree


Hi guys,
Im having trouble with my remove function in my binary search tree, i can delete a node which has left or right nodes but not one that has both(left and right)

Here is my function

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
void Bst::remove(Bst *&parent, int &num ){
	
	Bst *temp, *root; 
	
	temp=parent;
	
	if (parent==NULL) {
		cout << "Nothing to delete";
	}
	else if (parent->info == num){
	 if (parent->right==NULL&&parent->left==NULL){
	 temp = parent;
	 parent = NULL;
	 delete temp;
	 }
	 else if(parent->right==NULL){
	 temp = parent;
	 parent = parent->left;
	 delete temp;
	 
	 }
	 else if(parent->left==NULL){
	 temp = parent;
	 parent = parent->right;
	 delete temp;
	 }
	}
	 else if (num < parent->info) {
		 root = parent;
		 remove(parent->left, num);
	 }
	 else {
		 root = parent;
		 remove(parent->right, num);
	 }	
	
}



Appreciate any help i can get

Topic archived. No new replies allowed.