Advertisement
Glenpl

alphabetic sort algorithm

Feb 7th, 2015
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <string>
  6. void print(const std::string& item)
  7. {
  8.     printf("%s\n", item.c_str());
  9. }
  10. int main()
  11. {
  12.     std::vector<std::string> sortedItems;
  13.     std::string name;
  14.     while(std::cin >> name)
  15.         sortedItems.push_back(name);
  16.     std::sort(sortedItems.begin(), sortedItems.end());
  17.     std::for_each(sortedItems.begin(), sortedItems.end(), &print);
  18.     return 0;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement