Please help me with these 3 functions Im so lost even pseudo
Please help me with these 3 functions? I\'m so lost even pseudocode would help. I\'m making an autocomplete program in c++. I\'m not sure what they mean by \"that\" in the parameters. I\'ve got stuff printing right, I just don\'t know how to finish the term and autocomplete files.
https://www.cs.princeton.edu/courses/archive/fall16/cos226/assignments/autocomplete.html My teacher stole this and removed part 2, but this is basically my project.
void Autocomplete::insert(Term newterm)
{
// inserts the newterm to the sequence
terms.push_back(newterm);
}
vector<Term> Autocomplete::allMatches(string prefix) {
// returns all terms that start with the given prefix,
// in descending order of weight
vector<Term> V;
return V;
}
void Autocomplete::Search(string key, int & first, int & last)
{
// first: the index of the first query that equals
// the search key, or -1 if no such key
// last: the index of the last query that equals
// the search key, or -1 if no such key
}
int Autocomplete::BS_helper(vector<Term> terms, string key, int left, int right)
{
// return the index number of the search key using binary search algorithm
return 0;
}
I\'m lost on how to do thse and will take any and all help. Please please help me.
Solution
Now, the URL you have mentioned is returning 404 so could not get through, but looking into the code given below, I can dervive the following things which can you move ahead.
Firstly, taking the parameters,
1. void Autocomplete::insert(Term newterm) - > Term is user defined Class. You would pass the entire object of the term. This function creates an list of the Terms which would create an small repostiory for searching the terms in the autocomplete feature.
2. vector<Term> Autocomplete::allMatches(string prefix) - > prefix is the string which the user would insert. This string would be matched with the terms available with us. It is quite similar to Google search, so when you go to google search, you type \"apple\" in the text box and google matches this word with its repository, in this case apple would be the prefix string. The function would be returning all the matches respective to the string.
3. void Autocomplete::Search(string key, int & first, int & last) -> This is the search function which gives us the index of the matches found for the search key we have entered.
4. int Autocomplete::BS_helper(vector<Term> terms, string key, int left, int right) -> This is the main function which would hold the binary search function for the key to be searched.
So as per me the flow of the functions should be like:
1. void Autocomplete::insert
2. vector<Term> Autocomplete::allMatches
- > inside this function we would call void Autocomplete::Search
-> -> inside the Search function call the int Autocomplete::BS_helper function.

