0
void Delete(TreeNode* tree, ItemType item)
	 {
			
		 
		 if (item.ComparedTo (tree->info)==LESS)
    		Delete(tree->left, item);   
		 else if (item.ComparedTo( tree->info)==GREATER)
    		Delete(tree->right, item);  
  	else
    		DeleteNode(tree);  // Node found
	} 

		
	 void GetPredecessor(TreeNode* tree,  ItemType& data) 
  // Sets data to the info member of the right-most node in tree.
{
	while (tree->right != NULL)
   		tree = tree->right;
  		data = tree->info;
}

	 void DeleteNode(TreeNode* tree)
	 {	

		  TreeNode* tempPtr;
		  tempPtr = tree;
		  if(tree->left == NULL&&tree->right==NULL)
			 delete tempPtr;
		  else if (tree->left == NULL) 
		  {
			tree = tree->right;
			delete tempPtr;
		  }
		  else if (tree->right == NULL)
		  {
			tree = tree->left;
			delete tempPtr;
		  }

			else
		 {
			GetPredecessor(tree->left, item);
			tree->info =item;
			Delete(tree->left, item);
		  }
	  }

so when i was delete the leaf don't work
so what can i do
with my regardes

Edited by WaltP: Added CODE tags -- with all the help about them, how could you miss using them????

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Narue
0

Perhaps I was too subtle. Please allow me to try again.

[take 2]
Your code is wrong. It has very basic mistakes. You lack fundamentals. Read the tutorial, dammit.
[/take 2]

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.