balancing in search tree in c++

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2009
Posts: 3
Reputation: Nika01 is an unknown quantity at this point 
Solved Threads: 0
Nika01 Nika01 is offline Offline
Newbie Poster

balancing in search tree in c++

 
0
  #1
Nov 4th, 2009
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;
}
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 404
Reputation: Clinton Portis is on a distinguished road 
Solved Threads: 40
Clinton Portis's Avatar
Clinton Portis Clinton Portis is offline Offline
Posting Pro in Training
 
0
  #2
Nov 4th, 2009
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.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC