本文整理汇总了C++中BST::Print方法的典型用法代码示例。如果您正苦于以下问题:C++ BST::Print方法的具体用法?C++ BST::Print怎么用?C++ BST::Print使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BST
的用法示例。
在下文中一共展示了BST::Print方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc,char **argv)
{
// Create an empty Binary Search Tree
BST Tree;
string input = "";
while (input !="ENDINSERT")
{
cin >> input;
if (input != "ENDINSERT")
Tree.Insert(input);
}
Tree.Print("POST");
}
示例2: main
int main(int argc,char **argv)
{
// Create an empty Binary Search Tree
BST Tree;
string input;
cin >> input;
while(input != "ENDINSERT") {
//cout << "got here" << endl;
Tree.Insert(input);
cin >> input;
}
//cout << "done inserting" << endl;
Tree.Print("POST");
}
示例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;
//Tree=new BST();
string input;
cin>>input;
while(input!="ENDINSERT"){
Tree.Insert(input);
cin>>input;
}
Tree.Print("POST");
}
示例5: 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");
}
示例6: main
//.........这里部分代码省略.........
{
bst.DeleteItem(input);
cout << endl << input << " is removed!" << endl << endl;
}
catch(NotFound)
{
cout << endl << "Number was not found!" << endl << endl;
}
}
else
{
cout << "What is the string you would like to remove?" << endl;
cin.ignore();
getline(cin, temp);
input = (char*)temp.c_str();
try
{
bst.DeleteItem(input);
cout << endl << input << " is removed!" << endl << endl;
}
catch(NotFound)
{
cout << endl << "String was not found!" << endl << endl;
}
}
command = 'M';
}
else if (command == 'D' || command == 'd')
{
if (!bst.IsEmpty())
{
cout << endl << "Displaying..." << endl;
bst.Print(cout);
cout << endl << endl;
bool finished = false;
bst.ResetTree(IN_ORDER);
cout << "InOrder: ";
while(!finished)
cout << bst.GetNextItem(IN_ORDER, finished) << " ";
finished = false;
bst.ResetTree(PRE_ORDER);
cout << endl << "PreOrder: ";
while(!finished)
cout << bst.GetNextItem(PRE_ORDER, finished) << " ";
finished = false;
bst.ResetTree(POST_ORDER);
cout << endl << "PostOrder: ";
while(!finished)
cout << bst.GetNextItem(POST_ORDER, finished) << " ";
cout << endl << endl;
}
else
cout << "The tree is empty!" << endl << endl;
command = 'M';
}
else if (command == 'C' || command == 'c')
{
cout << endl << "Chopping...Timber!" << endl;
bst.MakeEmpty();
cout << "Tree is empty!" << endl << endl;