Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <vector>
- using std::vector;
- class UnsortedSequence{
- public:
- vector<int> getUnsorted(vector<int>);
- };
- vector<int> UnsortedSequence::getUnsorted(vector<int> S){
- stable_sort(S.begin(),S.end());
- int i = S.size()-1;
- while(i>=0){
- if (S[i] < S[S.size()-1])
- break;
- i--;
- }
- if(i < 0) return vector<int>();
- int temp = S[i+1];
- S[i+1] = S[i];
- S[i] = temp;
- return S;
- }
Advertisement
Add Comment
Please, Sign In to add comment