Repository navigation
Expand file tree
/
Copy pathprog1.cpp
More file actions
88 lines (77 loc) · 2.62 KB
/
Copy pathprog1.cpp
File metadata and controls
88 lines (77 loc) · 2.62 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
// prog1.cpp
#include "wordTable.h"
#include "wordBST.h"
#include <fstream>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main(int argc, char *argv[]) {
WordTable wordList1;
WordBST wordList2;
ifstream textFile;
textFile.open("/autograder/submission/PA1_dataset.txt");
//textFile.open("PA1_dataset.txt");
string word;
char wordChar[100];
int count;
if (textFile.fail()) {
cerr << "Could not open file 'PA1_dataset.txt.'";
exit(1);
}
while (!textFile.eof() && !textFile.fail() && count < 9999) {
count++;
textFile >> wordChar;
wordList1.insertWord2(wordChar);
wordList2.insertWord2(wordChar);
}
textFile.close();
string argument = argv[1] ;
string::iterator it = argument.begin();
string subword, sub;
vector<string> commands;
for (it; it != argument.end(); it++) {
if (subword.length() > 5)
sub = subword.substr(subword.length() - 4, 4);
if (subword == "search" || subword == "delete" || subword == "insert" || subword == "range search") {
commands.push_back(subword);
subword.clear();
}
else {
if(*it == ',') {
commands.push_back(subword);
subword.clear();
it++;
}
else if (sub == " to ") {
subword = subword.substr(0, subword.length() - 4);
commands.push_back(subword);
subword.clear();
sub.clear();
subword += *it;
}
else
subword += *it;
}
}
commands.push_back(subword);
for (int vecIt = 0; vecIt < commands.size(); vecIt++) {
if (commands[vecIt] == "range search") {
wordList1.rangeSearch(commands[vecIt + 1], commands[vecIt + 2]);
wordList2.rangeSearch(wordList2.root, commands[vecIt + 1], commands[vecIt + 2] );
}
else if (commands[vecIt] == "delete") {
wordList1.deleteWord(commands[vecIt + 1]);
wordList2.deleteWord(commands[vecIt + 1]);
}
else if (commands[vecIt] == "insert") {
wordList1.insertWord(commands[vecIt + 1]);
wordList2.insertWord(commands[vecIt + 1]);
}
else if (commands[vecIt] == "search") {
wordList1.searchWord(commands[vecIt + 1]);
wordList2.searchWord(commands[vecIt + 1]);
}
}
}