Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Plain Text by Subhajit Bandyopadhyay ( 14 years ago )
1. scan the array from right-to-left (indices descending from N-1 to 0)

1.1. if the current element is less than its right-hand neighbor,
     call the current element the pivot,
     and stop scanning

1.2. if the left end is reached without finding a pivot,
     reverse the array and return
     (the permutation was the lexicographically last, so its time to start over)

2. scan the array from right-to-left again,
   to find the rightmost element larger than the pivot
   (call that one the successor)

3. swap the pivot and the successor

4. reverse the portion of the array to the right of where the pivot was found

5. return

 

Revise this Paste

Your Name: Code Language: