a53

prev_perm

a53
Feb 8th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.20 KB | None | 0 0
  1. void prev_perm(int n,int P[])
  2. {
  3. int i=n;
  4. while(i>1 && P[i-1]<=P[i])
  5. --i;
  6. int j=i-1;
  7. while(j+1<=n&&P[j+1]<=P[i-1])
  8. ++j;
  9. swap(P[i-1],P[j]);
  10. reverse(P+i,P+n+1);
  11. }
Advertisement
Add Comment
Please, Sign In to add comment