本文整理汇总了C++中BSTree类的典型用法代码示例。如果您正苦于以下问题:C++ BSTree类的具体用法?C++ BSTree怎么用?C++ BSTree使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BSTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
int N=0;
cin>>N;
char ins[20];
int a,b;
BSTree tree;
for(int i=0;i<N;i++)
{
cin>>ins;
if(ins[0]=='i')
{
cin>>a;
tree.insertData(a);
//tree.printByInOrderTraversal();
}
if(ins[0]=='d')
{
if(ins[6]=='\0')
{
cin>>a;
tree.deletion(a);
//tree.printByInOrderTraversal();
}
else
{
if(ins[7]=='l')
示例2: main
int main(){
const int input[] = {8, 58, 71, 18, 31, 32, 63, 92, 43, 3, 91, 93, 25, 80, 28};
// output should be array of {18 63 80 25 32 43 80 93 80 25 93 -1 28 -1 -1}
const int arraysize = sizeof(input) / sizeof(input[0]);
print_array(input, arraysize);
// test naive method
int output[arraysize];
replace_with_least_greater_number(input, arraysize, output);
print_array(output, arraysize);
// test BST method
int output2[arraysize];
BSTree tree;
for(int i= arraysize-1; i>=0; i--){
Node* least_greater_predecessor = tree.insert(input[i]);
if (least_greater_predecessor == NULL){
output2[i] = -1;
}else{
output2[i] = least_greater_predecessor->value;
}
}
//tree.print_tree();
print_array(output2, arraysize);
return 0;
}
示例3: main
int main()
{
BSTree<int> bstree;
TreeNode<int>* ptn;
bstree.insert(3);
bstree.insert(3);
bstree.insert(1);
bstree.insert(7);
bstree.insert(5);
bstree.insert(8);
bstree.print(std::cout);
ptn = bstree.find_min(0);
std::cout << "\nThe minimum element is " << ptn->element << std::endl;
ptn = bstree.find_max(0);
std::cout << "\nThe maximum element is " << ptn->element << std::endl;
bstree.delete_element(3);
bstree.print(std::cout);
return 0;
}
示例4: main
int main()
{
int num;
BSTree T;
cin >> num;
while( num != -1 )
{
T.insert(num);
cin >> num;
}
T.median();
}
示例5: Test2
void Test2()
{
int a[] = { 5, 3, 4, 1, 7, 8, 2, 6, 0, 9 };
BSTree<int, int> bst;
for (int i = 0; i < (sizeof(a) / sizeof(a[0])); ++i)
{
bst.InsertR(a[i], i);
}
bst.Inorder();
cout << bst.FindR(0)->_key << endl;
cout << bst.RemoveR(3) << endl;
}
示例6: Test1
void Test1()
{
int a[] = { 5, 3, 4, 1, 7, 8, 2, 6, 0, 9 };
BSTree<int, int> bst;
for (int i = 0; i < (sizeof(a) / sizeof(a[0])); ++i)
{
bst.Insert(a[i], i);
}
bst.Inorder();
//cout << bst.Find(10)->_key << endl;
cout << "------------------------------------------" << endl;
cout<<bst.Remove(8)<<endl;
bst.Inorder();
}
示例7: main
int main()
{
BSTree T;
int n;
cin >> n;
while(n!=-1)
{
T.insert(n);
cin >> n;
}
cin >> T.max;
T.pathsum(T.root);
cout << T.count << endl;
}
示例8: SetTreePositions
//template <typename T>
void SetTreePositions(const BSTree &tree,
std::map<const BSTree::BinTreeNode *,
std::pair<int, int> >& NodePositions)
{
Position = 0;
NodePositions.clear();
SetTreePositions(tree.root(), 0, NodePositions);
}
示例9: main
int main() {
BSTree tree;
tree.Insert(8);
tree.Insert(6);
tree.Insert(10);
tree.Insert(5);
tree.Insert(7);
tree.Insert(9);
tree.Insert(11);
tree.BreadthFirstTraversal();
//tree.Rotate();
//tree.BreadthFirstTraversal();
tree.RotateIterative2();
tree.BreadthFirstTraversal();
}
示例10: main
int main()
{
BSTreeNode * pHead = NULL;
BSTreeNode * pListIndex = NULL;
BSTree* pRoot = new BSTree();
pRoot->addBSTreeNode(10);
pRoot->addBSTreeNode(4);
pRoot->addBSTreeNode(12);
pRoot->addBSTreeNode(14);
pRoot->addBSTreeNode(15);
pRoot->addBSTreeNode(6);
pRoot->addBSTreeNode(8);
pRoot->addBSTreeNode(16);
pRoot->showTree(); // 树的形状
pRoot->ergodicBSTree();
return 0;
}
示例11: initValues
void initValues(vector <int>& v, BSTree& root, HashTable& ht) {
int i, randomValue;
bool hashTableFull;
for (i = 0; i < size; i++) {
randomValue = 1 + rand() % 99;
v.push_back(randomValue);
root.insert(randomValue);
hashTableFull = ht.insert(randomValue);
if (!hashTableFull) cout << "Hash Table is now full." << endl;
}
}
示例12: Execute
void WithdrawlOrder::Execute(BSTree &accounts)
{
Account* temp;
if (accounts.Retrieve(accountID, temp))
{
temp->Withdraw(amount, fundNumber);
}
else
{
cerr << "ERROR: Account " << accountID << " not found. Withdrawl refused." << endl;
}
}
示例13: main
int main() {
BSTree<int> tree;
tree.add(15, 15);
tree.add(8, 8);
tree.add(6, 6);
tree.add(7, 7);
tree.add(12, 12);
tree.add(11, 11);
tree.add(9, 9);
tree.add(20, 20);
tree.add(18, 18);
tree.add(25, 25);
tree.add(23, 23);
tree.traverse(TraverseOrder::MID_ORDER);
tree.traverse(TraverseOrder::PRE_ORDER);
return 0;
}
示例14: Test1
void Test1()
{
BSTree<int, int> b;
int a[] = { 1, 3, 6, 7, 2, 8, 0 };
for (int i = 0; i < sizeof(a) / sizeof(a[0]); ++i)
{
b.InsertR(a[i], i);
}
b.InOder();
cout<<b.IsBlanceTree()<<endl;
b.RemoveR(7);
b.RemoveR(6);
b.RemoveR(8);
b.RemoveR(0);
b.RemoveR(3);
b.RemoveR(2);
b.RemoveR(1);
b.InOder();
return;
}
示例15: main
int main(int args,char* argv[]){
BSTree * myTree = new BSTree;
myTree->Insert(80);
myTree->Insert(43);
myTree->Insert(21);
myTree->Insert(42);
myTree->Insert(20);
myTree->Insert(50);
myTree->Insert(6);
myTree->Insert(74);
myTree->Insert(12);
myTree->Insert(78);
myTree->Insert(52);
myTree->InOrder();
cout << endl;
myTree->PostOrder();
cout << endl;
myTree->PreOrder();
cin.get();
return 0;
}