mini programmer 0 Junior Poster in Training

Hi to all
I have ADT of the AVL TREE and I need to add some the function to create tree to family.

I have logic error in my code..
my code work to find relationship between two nodes (e.g: a parent of b,a and b are Sibling and so on)
but it doesn't work correctly

look at this function which find if the nodes are Sibling or no:

firstly,in function main I wrote:
.
.
.

cout <<"Please, Enter the two names that ";
		cin >>ObjectPerson1.key >> ObjectPerson2.key;

		if ( !ObjectAvlTree.AVL_Retrieve (ObjectPerson1.key , ObjectPerson) || !ObjectAvlTree.AVL_Retrieve (ObjectPerson2.key , ObjectPerson) )
		{

			if (! ObjectAvlTree.AVL_Retrieve (ObjectPerson1.key , ObjectPerson))
				cout <<endl<< ObjectPerson1.key << " is not found in this Family Tree.";
			if(! ObjectAvlTree.AVL_Retrieve(ObjectPerson2.key , ObjectPerson))
				cout <<endl<< ObjectPerson2.key << " is not found in this Family Tree.";
		}
		else 
		
		{
			if(ObjectAvlTree.IsSibiling(ObjectPerson1.key,ObjectPerson2.key))
				cout<<ObjectPerson1.key<<" and "<<ObjectPerson2.key<<" sibling\n";

.
.
.
.

and in my class of ADT:
.
.

// public
.

bool AvlTree<TYPE,KTYPE>:: IsSibiling (KTYPE key1 , KTYPE key2) //public funcion
{ 
	// Local Definitions
	bool status;
	
	// Statements
	if (! tree)
		return false;

	status = _IsSibiling_ (key1 , key2 , tree);
	if (status)
	
		return true;
	 // if found
	else
		return false;
} // AVL_Retrieve_

.
.
.
// private

bool AvlTree<TYPE, KTYPE>::__IsSibiling__ (KTYPE key1 , KTYPE key2 , NODE<TYPE> * root)//private function
{ NODE<TYPE> *Ppre;
Ppre=root;

	// statements
	if (root)
	{
		if (! (( (key1 < root->data.key) && (key2 > root->data.key)) || !( (key1 > root->data.key) && (key2 < root->data.key) )))
		{
		  if (key1 < root->data.key)
		  {Ppre=root;
			return __IsSibiling__ (key1 , key2, root->left);
		  }
		  else if (key1 > root->data.key)
			  {Ppre=root;
			return __IsSibiling__ (key1,key2, root->right);
		      }
		  }
		  else
		  {// Found equal key
			  if(Ppre->right->data.key == key2  || Ppre->left->data.key == key2 )
			  return true;
			  else 
		      return false;
		}
	} 
	else
		//Data not in tree
		return false;
}// _retrieve_

the logic error is print invert. if the nodes is Sibling its print no Sibling , and if no Sibling its print Sibling


I hope to help me


greeting

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.