Is This Correct Method?


#1
vector<vector<int> > Solution::permute(vector<int> &A) {
int i=1;
vector<vector<int>>c;
sort(A.begin(),A.end());
c.push_back(A);
while(i){
    for(i=A.size()-1;i>0;i--){
        if(A[i-1]<A[i])
            break;
    }

    if(i == 0)
        return c;

    else {
        int n= A[i-1],index =i;
        for(int j=i;j<A.size();j++){
            if(A[j]>n && A[j]<A[index])
                index = j;
        }
        swap(A[i-1],A[index]);
        sort(A.begin()+i,A.end());
    }
    c.push_back(A);
   }
}