Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "TreeType.h"
- using namespace std;
- int main()
- {
- char command; //menu command
- char item; //user's item
- TreeType tree;
- string orderItem;
- //order,orderItem,PRE_ORDER,IN_ORDER,POST_ORDER;
- bool found = false;
- bool finished = false;
- OrderType order;
- ItemType ret;
- string words;
- do {
- cout <<"Choose what to do: \n";
- cout <<"-------------------------\n";
- cout <<"A: PutItem\n";
- cout <<"D: DeleteItem\n";
- cout <<"S: GetItem\n";
- cout <<"I: info. length, IsEmpty, IsFull\n";
- cout <<"P: PrintTree\n";
- cout <<"R: (Iterator) ResetTree, GetNextItem\n";
- cout <<"C: MakeEmpty\n";
- cout <<"O: Build tree using array\n";
- cout <<"E: Quit\n";
- cout <<"-------------------------\n";
- cin >> command;
- switch (command)
- {
- case 'A':
- cout <<"Enter a char to insert:\n";
- cin >> item;
- tree.GetItem(item, found);
- if (found)
- cout << item << " already in list." << endl;
- else
- {
- tree.PutItem(item);
- cout << item;
- cout << " is inserted" << endl;
- }
- break;
- case 'D':
- cout <<"Enter a char to delete:\n";
- cin >> item;
- tree.DeleteItem(item);
- cout << item;
- cout << " is deleted" << endl;
- break;
- case 'S':
- cout <<"Enter a char to search:\n";
- cin >> item;
- tree.GetItem(item, found);
- if (found)
- cout << item << " found in list." << endl;
- else cout << item << " not in list." << endl;
- break;
- case 'I':
- if (tree.IsEmpty())
- cout << "Tree is empty." << endl;
- else cout << "Tree is not empty." << endl;
- if (tree.IsFull())
- cout << "Tree is full." << endl;
- else
- cout << "Tree is not full." << endl;
- break;
- case 'P':
- // tree.Print(outFile);
- break;
- case 'R':
- cout <<"traversal order (preorder, inorder or postorder)";
- cin >> orderItem;
- if (orderItem == "preorder")
- order = PRE_ORDER;
- else if (orderItem == "inorder")
- order = IN_ORDER;
- else order= POST_ORDER;
- cout <<"traversing nodes in the given order:";
- tree.ResetTree(order);
- do {
- tree.GetNextItem(order,finished);
- cout << item;
- } while (!finished);
- cout << endl;
- break;
- case 'C':
- tree.MakeEmpty();
- cout << "Tree has been made empty." << endl;
- break;
- case 'O':
- cout <<"Enter a string...";
- cin >> words;
- tree.MakeEmpty();
- for (int i=0;i<words.length();i++)
- {
- ret=tree.GetItem(words[i], found);
- if (found)
- tree.PutItem (words[i]);
- }
- break;
- case 'E':
- cout <<"Ok, Exiting\n";
- break;
- default:
- cout << " Command not recognized." << endl;
- }
- } while (command != 'E');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement