Implementing a search input suggestion generator with tries
When entering something into a search engine on the Internet, the interface often tries to guess how the full search query will look. This guessing is usually based on popular search queries from the past. Sometimes, such search engine guesses are quite funny because it appears that people type weird queries into search engines.
In this section, we are going to use the trie class that we implemented in the previous recipe and build a little search query suggestion engine.
How to do it...
In this section, we will implement a terminal app, which accepts some input and then tries to guess what the user might want to look for, based on a cheap text file database:
- As always, includes come first, and we define that we use the
std
namespace:
#include <iostream> #include <optional> #include <algorithm> #include <functional> #include <iterator> #include <map> #include...