944,085 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 417
  • C++ RSS
Nov 4th, 2009
0

balancing in search tree in c++

Expand Post »
Helllo,,please,help me,to write programm add balance,delete balance in search tree,
TreeNode *AddBalance (Type x,TreeNode *root,int *grow)
{int incr;
*grow = 0;
if (!root)
{root=(TreeNode*) GetPlace();
if (root)
{root->left=root->right=0;
root->value=x; root->balance=0;
*grow=1;
}
return root;
}
if (x<=root->value)
{root->left=AddBalance(x,root->left,&incr);
if (incr)
{switch(root->balance)
{case 0:root->balance=-1;*grow=1;break;
case 1:root->balance=0;break;
case -1:
switch(root->left->balance)
{case -1:root=Rebuild_L1(root);break;
case 1:root=Rebuild_L2(root);
}
}
}
}
else {root->right=AddBalance(x,root->right,&incr);
if(incr)
{switch(root->balance)
{case 0:root->balance=-1;*grow=1;break;
case -1:root->balance=0;break;
case 1:
switch(root->right->balance)
{case 1:root=Rebuild_L1(root);break;
case -1:root=Rebuild_L2(root);

}
}
}

}
return root;
}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Nika01 is offline Offline
3 posts
since Nov 2009
Nov 4th, 2009
0
Re: balancing in search tree in c++
You pose quite the intruiging and insightful question:

Binary Search Trees
Randomized Binary Search Trees
Balanced Binary Search Trees
Last edited by Clinton Portis; Nov 4th, 2009 at 8:47 pm.
Reputation Points: 237
Solved Threads: 117
Practically a Posting Shark
Clinton Portis is offline Offline
822 posts
since Oct 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Coin simulate
Next Thread in C++ Forum Timeline: traversing tree folder!!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC