a. Store 5 names in a list. Allow the user to input each name.
b. Sort the list alphabetically in ascending order and print the list.
c. Sort the list alphabetically in descending order and print the list.
d. Ensure your code can be executed without bugs or errors.
im stuck in sorting the list in descending order please help:(
below is my source code of the 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 i = 1; i <= 5; ++i)
{
std::string name;
std::cout << i << ". ";
std::cin >> name;
sortedItems.insert(name);
}
std::for_each(sortedItems.begin(), sortedItems.end(), &print);
return 0;
}