Deletings leaves with a certain value

I am trying to delete a leaf with a certain value from a binary tree. However when I delete the node,the program hangs. It would be great if i could get some pointers on removing leaves.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  template<class T>
void binSTree<T>::remove(Node<T>*& node, const T& x)
{
	if (node != NULL)
	{

		if (x == node->data)
		{
			if (leaf(node))
			{
				delete node;
			
			}
		}
		if (x < node->data)
		{
			remove(node->left, x)
		}
		else
			remove(node->right, x);	
}
Last edited on
What happens if you change line 15 from if to else if?
Topic archived. No new replies allowed.