First, the dictionary order method
1) from the right end of the sequence p, scan to the left until you find the first number that is smaller than the number on the right.
2) from the right, find all the smallest numbers in the larger number, ie.
3) Exchange with.
4) Flip the sequence on the right to get the next permutation of the dictionary order.
5) Repeat the above steps until you get the largest order in the dictionary order, that is, the left number is larger than the right.
Second, SJT algorithm
The initial state is.
1) Find the maximum movable number m (when a number points to a number smaller than it is, the number is the number of movable)
2) interchange M and m pointing to the number of
3) Change the direction of all numbers larger than M
4) Repeat the above steps until you cannot find the movable number
Third, Heap ' s algorithm
Procedure generate (N:integer, A:array of any): if n = 1 then output (A) else for i: = 1; i≤n; i + = 1 Do generate (n-1, A) if n was odd then j←1 else j←i swap (A[j], a[n])
The above algorithm description is excerpted from Wikipedia
Full permutation algorithm (dictionary order method, SJT algorithm, Heap ' s algorithm)