| | |
balancing in search tree in c++
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2009
Posts: 3
Reputation:
Solved Threads: 0
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;
}
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;
}
0
#2 Nov 4th, 2009
You pose quite the intruiging and insightful question:
Binary Search Trees
Randomized Binary Search Trees
Balanced Binary Search Trees
Binary Search Trees
Randomized Binary Search Trees
Balanced Binary Search Trees
Last edited by Clinton Portis; Nov 4th, 2009 at 8:47 pm.
![]() |
Similar Threads
- deleting a Binary search tree (C++)
- Reading a file into a binary search tree (C++)
- Binary Search Tree (C++)
- searching and inserting node in a binary search tree (C)
- recursive findaverage function for Binary search tree (C)
- Binary search tree removal (C++)
- Insertion in a binary search tree (C++)
Other Threads in the C++ Forum
- Previous Thread: Coin simulate
- Next Thread: traversing tree folder!!
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph homeworkhelp iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg simple sorting spoonfeeding string strings struct template templates text tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets





