Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #include <vector>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. vector <int> Pendulum (vector <int> values)
  7. {
  8. vector <int> Result;
  9. sort(values.begin(), values.end());
  10.  
  11. if( values.size() % 2 != 0)
  12. {
  13. for(int i = values.size() - 1; i >= 0; i--)
  14. {
  15. Result.push_back( values[i] );
  16. i--;
  17. }
  18. for(int i = 1; i < values.size(); i++)
  19. {
  20. Result.push_back( values[i] );
  21. i++;
  22. }
  23. }
  24.  
  25. else
  26. {
  27. for(int i = values.size() - 2; i >= 0; i--)
  28. {
  29. Result.push_back( values[i] );
  30. i--;
  31. }
  32. for(int i = 1; i < values.size(); i++)
  33. {
  34. Result.push_back( values[i] );
  35. i++;
  36. }
  37. }
  38.  
  39. return Result ;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement