Dsa C++
Dsa C++
#include <iostream>
#include <functional>
#include <string>
#include <cassert>
using namespace std;
class Term {
public:
string query;
long weight;
string getQuery()const{
return query;
}
};
-----------------------------------------------------------------------------
PART 2:
class BinarySearchDeluxe {
public:
template <typename Key>
static int firstIndexOf(const vector<Key>& a, const Key& key,
function<bool(const Key&, const Key&)> comparator) {
if (a.empty() || !comparator) {
throw invalid_argument("Array or comparator cannot be null.");
}
int firstindex = 0;
int lastindex = a.size() - 1;
int mid;
int firstindex = 0;
int lastindex = a.size() - 1;
int mid;
--------------------------------------------------------------------------------
PART 3:
class Autocomplete {
private:
std::vector<Term> terms;
public:
Autocomplete(const vector<Term>& terms) : terms(terms){}
Autocomplete autocomplete(terms);
int main() {
int n;
infile >> n;
vector<Term> terms;
Autocomplete autocomplete(terms);
string prefix;
cout<< "Enter prefix for Cities: "<< endl;
while (getline(cin, prefix)) {
vector<Term> results = autocomplete.allMatches(prefix);
cout << results.size() << " matches\n";
for (size_t i = 0; i < min(results.size(), static_cast<size_t>(5));
i++) {
cout << results[i].toString() << "\n";
}
}
return 0
}
-----------------------------------------------------------------------------------
-