fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm> // for sort
  4. #include <functional> // for less & greater
  5.  
  6. int main()
  7. {
  8. int x[10] = { 1,3,5,7,9,2,4,6,8,10 };
  9.  
  10. std::cout << "Ascending: " << std::endl;
  11. std::sort(x,x+10,std::less<int>());
  12. for(int i = 0; i < 10; ++i)
  13. std::cout << x[i] << " ";
  14.  
  15. std::cout << std::endl << "Descending: " << std::endl;
  16. std::sort(x,x+10,std::greater<int>());
  17. for(int i = 0; i < 10; ++i)
  18. std::cout << x[i] << " ";
  19. }
  20.  
Success #stdin #stdout 0s 2900KB
stdin
Standard input is empty
stdout
Ascending: 
1 2 3 4 5 6 7 8 9 10 
Descending: 
10 9 8 7 6 5 4 3 2 1