#include "gTree.h" #include #include #include #include using namespace std; void Tokenize(string line, vector & tokens, string delimiters = "\t "){ string token = ""; string OneCharString = " "; for (int i=0; i my_tree; string line; while (getline(inf, line).good()){ vector tokens; Tokenize(line, tokens, "\t "); if (tokens.size()==0) continue; if ((tokens[0][0]=='i') && (tokens[0][1]=='n')){ //insert gTNode* p = findItem(my_tree.getRoot(), tokens[1]); my_tree.addNode(tokens[2], p); } else if ((tokens[0][0]=='r') && (tokens[0][1]=='e')){ // remove gTNode* p = findItem(my_tree.getRoot(), tokens[1]); p->remove(); } else if ((tokens[0][0]=='p') && (tokens[0][1]=='r')){ cout << "preorder:\n"; preorderPrint(my_tree.getRoot()); cout << endl; } else if ((tokens[0][0]=='p') && (tokens[0][1]=='o')){ cout << "postorder:\n"; postorderPrint(my_tree.getRoot()); cout << endl; } else if ((tokens[0][0]=='g') && (tokens[0][1]=='e')){ //getSize cout << size(my_tree.getRoot()) << endl; } } inf.close(); } int main(int argc, char** argv){ if (argc!=2){ cout << "Usage: executable.o commands.txt\n"; return 1; } ExecuteCommands(argv[1]); }