c++ - Sort the list alphabetically in descending order and print the list -
c++ - Sort the list alphabetically in descending order and print the list -
a. store 5 names in list. allow user input each name. b. sort list alphabetically in ascending order , print list. c. sort list alphabetically in descending order , print list. d. ensure code can executed without bugs or errors.
im stuck in sorting list in descending order please help:(
below source code of ascending order.
#include <iostream> #include <set> #include <algorithm> void print(const std::string& item) { std::cout << item << std::endl; } int main() { std::set<std::string> sorteditems; for(int = 1; <= 5; ++i) { std::string name; std::cout << << ". "; std::cin >> name; sorteditems.insert(name); } std::for_each(sorteditems.begin(), sorteditems.end(), &print); homecoming 0; }
to display set
in reverse order, may use:
std::for_each(sorteditems.rbegin(), sorteditems.rend(), &print);
c++
Comments
Post a Comment