-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
89 lines (67 loc) · 1.98 KB
/
main.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
#include "Hash_Table.hpp"
int main();
int main() {
Hash_Table* hash_table;
string cmd;
while( cin >> cmd ) {
if( cmd == "M" ) {
int size = 0;
cin >> size;
hash_table = new Hash_Table( size );
cout << "success" << endl;
}
else if( cmd == "INSERT" ) {
string word;
cin >> word;
if( hash_table->insert( word ) ) {
cout << "success" << endl;
} else {
cout << "failure" << endl;
}
}
else if( cmd == "READ" ) {
string filename;
cin >> filename;
fstream fin( filename.c_str() );
if( hash_table->read_file( fin ) ){
cout << "success" << endl;
} else {
cout << "failure" << endl;
}
fin.close();
}
else if( cmd == "TOKENIZE" ) {
string word;
cin >> word;
int token_of_word = hash_table->tokenize( word );
cout << token_of_word << endl;
}
else if( cmd == "RETRIEVE" ) {
int token;
cin >> token;
string word_with_token = hash_table->retrieve( token );
cout << word_with_token << endl;
}
else if( cmd == "STOK" ) {
string sentence;
cin.ignore();
getline( cin , sentence );
hash_table->tokenize_string( sentence );
}
else if( cmd == "TOKS" ) {
string tokens;
cin.ignore();
getline( cin , tokens );
hash_table->retrieve_string( tokens );
}
else if( cmd == "PRINT" ) {
int position;
cin >> position;
hash_table->print_keys_at( position );
}
else if( cmd == "EXIT" ) {
delete hash_table;
return 0;
}
}
}