Advertisement
Guest User

main.cpp

a guest
Dec 5th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. #include <iostream>
  2. #include "TreeType.h"
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. char command; //menu command
  8. char item; //user's item
  9. TreeType tree;
  10. string orderItem;
  11. //order,orderItem,PRE_ORDER,IN_ORDER,POST_ORDER;
  12. bool found = false;
  13. bool finished = false;
  14. OrderType order;
  15. ItemType ret;
  16. string words;
  17.  
  18. do {
  19. cout <<"Choose what to do: \n";
  20. cout <<"-------------------------\n";
  21. cout <<"A: PutItem\n";
  22. cout <<"D: DeleteItem\n";
  23. cout <<"S: GetItem\n";
  24. cout <<"I: info. length, IsEmpty, IsFull\n";
  25. cout <<"P: PrintTree\n";
  26. cout <<"R: (Iterator) ResetTree, GetNextItem\n";
  27. cout <<"C: MakeEmpty\n";
  28. cout <<"O: Build tree using array\n";
  29. cout <<"E: Quit\n";
  30. cout <<"-------------------------\n";
  31.  
  32. cin >> command;
  33. switch (command)
  34. {
  35. case 'A':
  36. cout <<"Enter a char to insert:\n";
  37. cin >> item;
  38.  
  39. tree.GetItem(item, found);
  40. if (found)
  41. cout << item << " already in list." << endl;
  42. else
  43. {
  44. tree.PutItem(item);
  45. cout << item;
  46. cout << " is inserted" << endl;
  47. }
  48. break;
  49. case 'D':
  50. cout <<"Enter a char to delete:\n";
  51. cin >> item;
  52. tree.DeleteItem(item);
  53. cout << item;
  54. cout << " is deleted" << endl;
  55. break;
  56. case 'S':
  57. cout <<"Enter a char to search:\n";
  58. cin >> item;
  59.  
  60. tree.GetItem(item, found);
  61. if (found)
  62. cout << item << " found in list." << endl;
  63. else cout << item << " not in list." << endl;
  64. break;
  65. case 'I':
  66. if (tree.IsEmpty())
  67. cout << "Tree is empty." << endl;
  68. else cout << "Tree is not empty." << endl;
  69.  
  70. if (tree.IsFull())
  71. cout << "Tree is full." << endl;
  72. else
  73. cout << "Tree is not full." << endl;
  74. break;
  75. case 'P':
  76. // tree.Print(outFile);
  77. break;
  78.  
  79. case 'R':
  80. cout <<"traversal order (preorder, inorder or postorder)";
  81. cin >> orderItem;
  82. if (orderItem == "preorder")
  83. order = PRE_ORDER;
  84. else if (orderItem == "inorder")
  85. order = IN_ORDER;
  86. else order= POST_ORDER;
  87.  
  88. cout <<"traversing nodes in the given order:";
  89. tree.ResetTree(order);
  90. do {
  91. tree.GetNextItem(order,finished);
  92. cout << item;
  93. } while (!finished);
  94. cout << endl;
  95. break;
  96.  
  97. case 'C':
  98. tree.MakeEmpty();
  99. cout << "Tree has been made empty." << endl;
  100. break;
  101.  
  102. case 'O':
  103. cout <<"Enter a string...";
  104. cin >> words;
  105. tree.MakeEmpty();
  106. for (int i=0;i<words.length();i++)
  107. {
  108. ret=tree.GetItem(words[i], found);
  109. if (found)
  110. tree.PutItem (words[i]);
  111. }
  112. break;
  113.  
  114. case 'E':
  115. cout <<"Ok, Exiting\n";
  116. break;
  117. default:
  118. cout << " Command not recognized." << endl;
  119.  
  120. }
  121. } while (command != 'E');
  122.  
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement