tcbpg

Untitled

Jan 31st, 2012
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <vector>
  4. using std::vector;
  5.  
  6. class UnsortedSequence{
  7.     public:
  8.         vector<int> getUnsorted(vector<int>);
  9. };
  10.  
  11. vector<int> UnsortedSequence::getUnsorted(vector<int> S){
  12.     stable_sort(S.begin(),S.end());
  13.  
  14.     int i = S.size()-1;
  15.     while(i>=0){
  16.         if (S[i] < S[S.size()-1])
  17.             break;
  18.         i--;
  19.     }
  20.  
  21.     if(i < 0) return vector<int>();
  22.     int temp = S[i+1];
  23.     S[i+1] = S[i];
  24.     S[i] = temp;
  25.  
  26.     return S;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment