-
Notifications
You must be signed in to change notification settings - Fork 0
/
TreePuzzle.cpp
108 lines (100 loc) · 2.38 KB
/
TreePuzzle.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//Casey Rock
//10/31/2019
//This file contains the treePuzzle class
#include "treePuzzle.hpp"
#include <iostream>
#include <stdlib.h>
#include <fstream>
using namespace std;
treePuzzle::treePuzzle(int x, string sarr[],int k) {
tree = new BSTY();
for (int i = 0; i < x; i++) {
tree->insertit(sarr[i]);
}
if (k == 0) {
runMine1(true);
}
cout << endl<<"*******************************"<<endl<<"PREORDER " << endl;
tree->printTreePre();
cout << "*******************************"<<endl<<"INORDER " << endl;
tree->printTreeIO();
cout << "*******************************"<<endl<<"POSTORDER " << endl;
tree->printTreePost();
cout << endl;
if (k == 0) {
runMine1(false);
}
else if (k ==1){
runMine2();
}
}
treePuzzle::treePuzzle(string fname,int k) {
tree = new BSTY();
readFile2(fname,k);
cout << "*******************************"<<endl<<"INORDER " << endl;
tree->printTreeIO();
cout <<endl << "*******************************FIND" << endl;
tree->find("pichiciego");
tree->find("falanouc");
tree->find("blauwbok");
tree->find("dibatag");
tree->find("gharial");
tree->find("duarf");
tree->find("kinkajou");
tree->find("zyzzyva");
tree->find("tucutucu");
tree->find("tabanid");
tree->find("solenodon");
tree->find("axolotl");
}
void treePuzzle::readFile2(string fname, int size) {
ifstream file(fname.c_str());
string word;
string def;
int ct = 0;
while (!file.eof() && ct < size) {
file >> word;
//cout << word << endl;
getline(file,def);
def = def.substr(2);
tree->insertit(word);
//cout << def << endl;
}
}
void treePuzzle::runMine1(bool flag) {
if (flag) {
cout << "Mine " << endl;
tree->myPrint();
}
else {
cout << endl << "PART TWO " << endl;
tree->find("ocelot");
tree->find("perforated");
tree->find("sibylic");
tree->find("go");
}
}
void treePuzzle::runMine2() {
cout << "Mine2 " << endl;
cout << endl << "EXTRA CREDIT " << endl;
tree->remove("apple");
cout << "AFTER REMOVE:" << endl;
tree->printTreeIO();
cout <<endl << "NOW REMOVING " ;
tree->remove("noon");
cout << "AFTER REMOVE:" << endl;
tree->printTreeIO();
cout <<endl << "NOW REMOVING " ;
tree->remove("jack");
cout << "AFTER REMOVE:" << endl;
tree->printTreeIO();
cout <<endl << "NOW REMOVING " ;
tree->remove("xray");
cout << "AFTER REMOVE:" << endl;
tree->printTreeIO();
cout << endl << "MineEC: " << endl;
tree->myPrintEC();
}
treePuzzle::~treePuzzle() {
delete tree;
}