本文整理汇总了C++中BST::diameter方法的典型用法代码示例。如果您正苦于以下问题:C++ BST::diameter方法的具体用法?C++ BST::diameter怎么用?C++ BST::diameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BST
的用法示例。
在下文中一共展示了BST::diameter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
BST bst;
bst.insertNode(50);
bst.insertNode(30);
bst.insertNode(20);
bst.insertNode(40);
bst.insertNode(70);
bst.insertNode(60);
bst.insertNode(80);
bst.inorder();
cout << bst.diameter() << endl;
return 0;
}
示例2: main
int main(){
BST bst;
int node1,node2;
int data,sum;
char ans='y',ins='y';
int option;
do{
cout<<endl<<"Menu:"<<endl;
cout<<endl<<"1. Insert data in BST"<<endl;
cout<<endl<<"2. Count number of nodes in BST"<<endl;
cout<<endl<<"3. Catalan number of BST"<<endl;
cout<<endl<<"4. Inorder traversal of BST"<<endl;
cout<<endl<<"5. Preorder traversal of BST"<<endl;
cout<<endl<<"6. Postorder traversal of BST"<<endl;
cout<<endl<<"7. Postorder Iterative"<<endl;
cout<<endl<<"8. hasPathSum in BST"<<endl;
cout<<endl<<"9. Diameter of BST"<<endl;
cout<<endl<<"10. Minimum value in BST"<<endl;
cout<<endl<<"11. Search node in BST"<<endl;
cout<<endl<<"12. Parent of a node in BST"<<endl;
cout<<endl<<"13. Tree successor of a node in BST"<<endl;
cout<<endl<<"14. Depth of BST"<<endl;
cout<<endl<<"15. Check if tree is BST"<<endl;
cout<<endl<<"16. Find lowest common ancestors of two nodes in BST"<<endl;
cout<<endl<<"17. Check for similarity of two BSTs"<<endl;
cout<<endl<<"18. Print all possible paths in BST"<<endl;
cout<<endl<<"19. Delete node in BST"<<endl;
cout<<endl<<"20. Delete all nodes in BST"<<endl;
cin>>option;
switch(option){
case 1:
do{
cout<<endl<<"Enter the data"<<endl;
cin>>data;
bst.insert(data);
cout<<endl<<"Do you want to enter more data"<<endl;
cin>>ins;
}while(ins=='y'||ins=='Y');
break;
case 2:
cout<<endl<<"Number of nodes in BST are:"<<bst.count()<<endl;
break;
case 3:
cout<<endl<<"Number of binary trees possible with count"<<bst.count()<<" is :"<<bst.catalanNumber(bst.count())<<endl;
break;
case 4:
cout<<endl<<"Inorder"<<endl;
bst.inorder();
break;
case 5:
cout<<endl<<"Preorder"<<endl;
bst.preorder();
break;
case 6:
cout<<endl<<"Postorder"<<endl;
bst.postorder();
break;
case 7:
cout<<endl<<"Postorder Iterative"<<endl;
bst.postorderIterative();
break;
case 8:
cout<<endl<<"Enter the sum to check in BST"<<endl;
cin>>sum;
cout<<endl<<"Result:"<<bst.hasPathSum(sum)<<endl;
break;
case 9:
cout<<endl<<"Diameter of BST:"<<bst.diameter();
break;
case 10:
cout<<endl<<"Minimum value in BST:"<<bst.minimum()<<endl;
break;
case 11:
cout<<endl<<"Enter the element you want to search:"<<endl;
cin>>data;
cout<<bst.search(data);
break;
case 12:
cout<<endl<<"Enter the node data to find parent of:"<<endl;
cin>>data;
cout<<endl<<"Parent is:"<<endl<<bst.parentNode(data)<<endl;
break;
case 13:
cout<<"Enter node to find Tree successor for:"<<endl;
cin>>data;
cout<<bst.treeSuccessor(data);
break;
case 14:
cout<<endl<<"Maximum depth of BST:"<<bst.depth()<<endl;
break;
case 15:
bst.insertRandomForSecondBST(50);
bst.insertRandomForSecondBST(40);
bst.insertRandomForSecondBST(60);
bst.insertRandomForSecondBST(30);
bst.insertRandomForSecondBST(45);
bst.insertRandomForSecondBST(55);
bst.insertRandomForSecondBST(70);
bst.insertRandomForSecondBST(25);
bst.insertRandomForSecondBST(20);
//.........这里部分代码省略.........