-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.cpp
43 lines (40 loc) · 1.22 KB
/
search.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
//main
#include <iostream>
#include <string>
#include <fstream>
#include "trie.h"
#include "node.h"
int main(int argc, char const *argv[])
{
std::string data;
std::fstream dictionary;
Trie complete_query;
dictionary.open("dictionary.txt", std::fstream::in); //read dictionary file into trie tree structure
if (dictionary.is_open())
{
while (dictionary)
{
dictionary >> data;
complete_query.insert(data);
}
}
else
{
std::cout << "error: file not open." << std::endl;
return -1;
}
dictionary.close();
data.clear(); //clear string variable used for file input; string variable will read in user input
std::cout << "enter search query:" << std::endl;
std::getline(std::cin, data); //getline used over std::cin to catch spaces
complete_query.is_space(data); //checks whether there's a space in user query
std::cout << "your search options are: " << std::endl;
if (complete_query.getSpace() == true) //if a space exists, remove prefix and pass prefix only to search method
{
complete_query.remove_prefix(data);
complete_query.search(complete_query.break_string(data));
}
else //if no method exists, pass user's query to search method to auto-complete the query
complete_query.search(data);
return 0;
}