In this section, we are going to use linear and binary search algorithms on a small example data set:
- We first include all the necessary headers and declare that we use the std namespace:
#include <iostream> #include <vector> #include <list> #include <algorithm> #include <string> using namespace std;
- Our data set will consist of city structs, which just save a city's name, and its population count:
struct city { string name; unsigned population; };
- Search algorithms need to be able to compare one item to the other, so we overload the == operator for the city struct instances:
bool operator==(const city &a, const city &b) { return a.name == b.name && a.population == b.population; }
- We also want to print the