本文整理汇总了C++中BST::Delete方法的典型用法代码示例。如果您正苦于以下问题:C++ BST::Delete方法的具体用法?C++ BST::Delete怎么用?C++ BST::Delete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BST
的用法示例。
在下文中一共展示了BST::Delete方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
BST bst;
if(bst.Empty())
cout << "BST::Empty() works" << endl;
else
cout << "BST::Empty() doesn't work" << endl;
bst.Insert(0);
if(!bst.Empty())
cout << "BST::Empty() works" << endl;
else
cout << "BST::Empty() doesn't work" << endl;
if(bst.Delete(0))
cout << "BST::Delete(const int) works" << endl;
else
cout << "BST::Delete(const int) doesn't work" << endl;
if(!bst.Delete(-1))
cout << "BST::Delete(const int) works" << endl;
else
cout << "BST::Delete(const int) doesn't work" << endl;
for(int i = 0; i < 10; i++)
bst.Insert(i);
cout << bst.Min() << endl;
cout << bst.Max() << endl;
if(bst.SearchIter(0) && !bst.SearchIter(10))
cout << "BST::SearchIter(const int) works" << endl;
else
cout << "BST::SearchIter(const int) doesn't work" << endl;
if(bst.SearchRec(0) && !bst.SearchRec(10))
cout << "BST::SearchRec(const int) works" << endl;
else
cout << "BST::SearchRec(const int) doesn't work" << endl;
bst.Clear();
if(bst.Empty())
cout << "BST::Empty() works" << endl;
else
cout << "BST::Empty() doesn't work" << endl;
return 0;
} // end main()
示例2: closeAccount
void closeAccount(BST<int> B)
{
int id;
cout << "\tEnter the ID number of the account you wish to close: ";
cin >> id;
B.Delete(id);
cout << "\tAccount " << id << " is now closed." << endl;
}
示例3: main
void main() // key(pair사용시 data.first) = 노드의 이름 같은 개념, element(pair 사용시 data.second) = 노드의 고유 data
{
//declare the type of K, E
typedef int K;
typedef char E;
BST<K, E> HWbst; // Making BST class HWbst link every nodes
int menu = 0;
while (1)
{
// Menu //
cout << endl << " #### Choose Menu ####" << endl;
cout << "1. Insert 2. Delete 3. Print 4. Exit" << endl;
cin >> menu;
switch (menu)
{
case 1: // Insert Menu
{
pair<K, E> A; // new node's pair type data
cout << " *** 새로운 TreeNode의 Key : ";
cin >> A.first;
cout << " *** 새로운 TreeNode의 Element : ";
cin >> A.second;
HWbst.Insert(A); // use insert function
break;
}
case 2: // Delete Menu
{
int a = 0;
cout << " *** 삭제할 노드의 Key 입력 : ";
cin >> a;
HWbst.Delete(a);
break;
}
case 3: // Print all nodes by level order
{
HWbst.Print();
break;
}
case 4: // close this program
{
return;
}
}
}
}
示例4: main
int main(int argc,char **argv)
{
// Create an empty Binary Search Tree
BST Tree;
string input;
cin>>input;
while(input!="ENDINSERT"){
Tree.Insert(input);
cin>>input;
}
//Tree.Print("POST");
//cout<<"transition"<<endl;
cin>>input;
while(input!="ENDDELETE"){
Tree.Delete(input);
cin>>input;
}
Tree.Print("POST");
}
示例5: _tmain
int _tmain(int argc, _TCHAR* argv[])
{
//Binary Search Tree
int bstArraySize = 11;
int bstArray[] = { 15, 6, 18, 3, 7, 17, 20, 2, 13, 4, 9 };
cout << "BST Input Array: " ;
PrintArray(bstArray, bstArraySize);
BST myBST;
for (int i = 0; i < bstArraySize; i++)
myBST.Insert(myBST.root, bstArray[i]);
cout << "InOrderTreeWalk: ";
myBST.InOrderTreeWalk(myBST.root);
cout << endl;
cout << "PreOrderTreeWalk: ";
myBST.PreOrderTreeWalk(myBST.root);
cout << endl;
cout << "PostOrderTreeWalk: ";
myBST.PostOrderTreeWalk(myBST.root);
cout << endl;
myBST.Search(myBST.root, 100);
myBST.Search(myBST.root, 20);
myBST.Maximum(myBST.root);
myBST.Minimum(myBST.root);
myBST.SearchParent(myBST.root, 9);
cout << "Delete Node 15: ";
myBST.Delete(myBST.root, 15);
myBST.InOrderTreeWalk(myBST.root);
cout << endl;
cout << endl;
//Max Heap
int table[] = {16, 4, 10, 14, 7, 9, 3, 2, 8, 1, 0, 0, 0, 0};
int heapSize = 10;
int* maxHeapArray = new int[15];
for (int i = 0; i < heapSize; i++)
*(maxHeapArray + i) = table[i];
cout << "Max-Heap: ";
PrintArray(maxHeapArray, heapSize);
MaxHeap myMaxHeap;
myMaxHeap.MaxHeapify(maxHeapArray, heapSize, 1);
cout << "Max-Heapified 1: ";
PrintArray(maxHeapArray, heapSize);
for (int i = 0; i < heapSize; i++)
*(maxHeapArray + i) = table[i];
cout << "Max-Heap: ";
PrintArray(maxHeapArray, heapSize);
myMaxHeap.BuildHeap(maxHeapArray, heapSize);
cout << "BuildHeap: ";
PrintArray(maxHeapArray, heapSize);
cout << "HeapExtractMax: " << myMaxHeap.HeapExtractMax(maxHeapArray, heapSize) << endl;
cout << "Remaining: ";
PrintArray(maxHeapArray, heapSize - 1);
cout << "HeapInsert 32: \n";
myMaxHeap.HeapInsert(maxHeapArray, heapSize - 1, 32);
cout << "New Heap: ";
PrintArray(maxHeapArray, heapSize);
for (int i = 0; i < heapSize; i++)
*(maxHeapArray + i) = table[i];
cout << "Max-Heap: ";
PrintArray(maxHeapArray, heapSize);
myMaxHeap.HeapSort(maxHeapArray, heapSize);
cout << "HeapSort: ";
PrintArray(maxHeapArray, heapSize);
cout << endl;
//AVL tree
int avlArraySize =11;
//int avlArray[] = { 15, 6, 18, 3, 7, 17, 20, 2, 13, 4, 9 };
int avlArray[] = { 30, 50, 40, 60, 70, 17, 20, 2, 13, 4, 9 };
cout << "AVL Input Array: ";
PrintArray(avlArray, avlArraySize);
AVL myAVL;
for (int i = 0; i < avlArraySize; i++)
{
myAVL.Insert(myAVL.root, avlArray[i]);
myAVL.InOrderTreeWalk(myAVL.root);
cout << endl;
}
cout << "Delete 30: \n";
myAVL.Delete(myAVL.root, 30);
myAVL.InOrderTreeWalk(myAVL.root);
cout << endl;
cout << "Delete 13: \n";
myAVL.Delete(myAVL.root, 13);
myAVL.InOrderTreeWalk(myAVL.root);
cout << endl;
cout << "Delete 20: \n";
myAVL.Delete(myAVL.root, 20);
//.........这里部分代码省略.........