-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
114 lines (88 loc) · 3.54 KB
/
main.cpp
File metadata and controls
114 lines (88 loc) · 3.54 KB
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
107
108
109
110
111
112
113
114
//main.cpp:
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <fstream>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <ctime>
#include "trie.h"
void readFile(std::string filename, std::vector<std::string>*wordList);
int main(int argc, char* argv[]){
//Initializes the Trie trees for the different word list and insert function combinations.
Trie *TrieTree = new Trie();
//initializes the input.
std::string input;
//Word: 33
std::vector<std::string> wordList;
//Reads the file for the word list.
readFile("visualizationWordList.txt", &wordList);
//Loop to go throught the word list.
for(int i = 0; i < wordList.size(); i++){
//Inserts each word.
TrieTree->recursiveInsert(wordList[i]);
}
//Announces the ascend display.
std::cout << "This is the ascend function output:" << std::endl;
//runs the ascend function
TrieTree->ascend();
//Puts a new line in for spacing.
std::cout << std::endl;
//Puts a new line in for the next function.
std::cout << std::endl;
TrieTree->destroy();
//Announces the ascend display.
std::cout << "This shows the destroy function emptied the Trie for the recursive Insert:" << std::endl;
//Puts a new line in for spacing.
std::cout << std::endl;
//runs the ascend function
TrieTree->ascend();
//Puts a new line in for the next function.
std::cout << std::endl;
for(int i = 0; i < wordList.size(); i++){
//runs the recursive insert function.
TrieTree->insert(wordList[i]);
}
//Announces the ascend display.
std::cout << "This is the ascend function again to show proper recursive insertation:" << std::endl;
//runs the ascend function
TrieTree->ascend();
//Puts a new line in for the next function.
std::cout << std::endl;
//Puts a new line in for spacing.
std::cout << std::endl;
//Announces the descend display.
std::cout << "This is the descend function output:" << std::endl;
//runs the descend function.
TrieTree->descend();
//Puts a new line in for the next function.
std::cout << std::endl;
TrieTree->remove("buzzword");
bool output = TrieTree->search("buzzword");
std::cout << "Buzzword was removed so it should not be found by search:(The following will be the output from search) " << (output?"true":"false") << std::endl;
//Puts a new line in for spacing.
std::cout << std::endl;
output = TrieTree->search("yorgurt");
std::cout << "Yorgut was not removed so it should be found by search:(The following will be the output from search) " << (output?"true":"false") << std::endl;
//runs the visualization insert function.
TrieTree->visualize("graph_Visualization.dot");
}
void readFile(std::string filename, std::vector<std::string>*wordList){
// Opens the file for reading
std::ifstream file(filename);
// Creates a string to hold each line in temporarily
std::string str;
// Creates a string to hold each line in temporarily
std::string wordTemp;
// Iterates over the file, storing one line at a time into `str`
while (getline(file, str)) {
// Create a stringstream object with each line from the file
std::istringstream ss(str);
//Grabs the values from the line.
while(ss >> wordTemp){
//Places the word on the vector.
(*wordList).push_back(wordTemp);
}
}
}