Question: Recode orange sorting example such that it uses multimaps and upper_bound(), lower_bound() functions. // sorting oranges // converting vectors to multimaps #include #include #include #include
Recode orange sorting example such that it uses multimaps and upper_bound(), lower_bound() functions.
// sorting oranges // converting vectors to multimaps #include#include #include #include #include #include using std::cin; using std::cout; using std::endl; using std::string; using std::vector; enum class Variety {orange, pear, apple}; vector colors = {"red", "green", "yellow"}; struct Fruit{ Variety v; string color; // red, green or orange }; int main(){ srand(time(nullptr)); vector tree(rand()%100+1); for(auto f=tree.begin(); f!=tree.end(); ++f){ f->v = static_cast (rand() % 3); f->color = colors[rand()%3]; } cout << "Colors of the oranges: "; for(auto f=tree.begin(); f!=tree.end(); ++f) if(f->v == Variety::orange) cout << f->color << ", "; cout << endl; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
