本文整理汇总了C++中BST::display方法的典型用法代码示例。如果您正苦于以下问题:C++ BST::display方法的具体用法?C++ BST::display怎么用?C++ BST::display使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BST
的用法示例。
在下文中一共展示了BST::display方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(){
BST<int> ex;
int fx[]={6,3,9,2,1,4,5,8,10};
for(int i=0;i<sizeof(fx)/4;i++)
ex.addNode(fx[i]);
ex.display(2);
cout<<endl;
ex.deleteNode(10);
ex.display(2);
cout<<endl;
ex.deleteNode(2);
ex.display(2);
cout<<endl;
ex.deleteNode(4);
ex.display(2);
cout<<endl;
ex.deleteNode(6);
ex.display(2);
}
示例2: main
int main()
{
BST obj;
Node * newPtr = NULL,*k =NULL;
int data, flag=1,j;
while(flag)
{
cout<<"Menu\n1. Insert\n2. IN-ORDER Traversal\n3. PRE-ORDER Traversal\n4. POST-ORDER Traversal\n5. Search\n6. Find Min & Max\n7. Delete\n8. Display\n9. Exit\n";
int x;
cin>>x;
switch(x)
{
case 1:
cout<<"Enter Element to be added to TREE: ";
cin>>data;
newPtr = obj.createNewNode(data);
if(newPtr==NULL)
{
cout<<"Cannot create node!! ABORTING!!!\n";
system("pause");
exit(1);
}
obj.insert(newPtr);
break;
case 2:
cout<<"IN-ORDER Traversal:\n\n";
obj.inOrder(obj.getRoot());
break;
case 3:
cout<<"PRE-ORDER Traversal:\n\n";
obj.preOrder(obj.getRoot());
break;
case 4:
cout<<"POST-ORDER Traversal:\n\n";
obj.postOrder(obj.getRoot());
break;
case 5:
cout<<"Enter element to be searched for: ";
cin>>j;
k=obj.find(j);
if(k!=NULL)
cout<<k->getData()<<" is Found! \n";
else
cout<<"Node not found!!\n";
break;
case 6:
cout<<"\nMINIMUM = "<<obj.findMin(obj.getRoot())->getData();
cout<<"\nMAXIMUM = "<<obj.findMax(obj.getRoot())->getData();
break;
case 7:
cout<<"Enter the node to be deleted from tree: ";
cin>>j;
obj.deleteNode(j);
cout<<"The BST is now:\n\n";
obj.display(obj.getRoot(),4);
break;
case 8:
cout<<"The BST is now:\n\n";
obj.display(obj.getRoot(),4);
break;
case 9:
exit(0);
}
cout<<"\nDo you want to continue? [yes -> 1, No -> 0]";
cin>>flag;
system("cls");
}
return 0;
}