RosettaCodeData/Task/Sorting-algorithms-Pancake-.../00-TASK.txt

28 lines
944 B
Plaintext

{{Sorting Algorithm}}
;Task:
Sort an array of integers (of any convenient size) into ascending order using [[wp:Pancake sorting|Pancake sorting]].
In short, instead of individual elements being sorted, the only operation allowed is to "flip" one end of the list, like so:
Before: '''6 7 8 9''' 2 5 3 4 1
After: '''9 8 7 6''' 2 5 3 4 1
Only one end of the list can be flipped; this should be the low end, but the high end is okay if it's easier to code or works better, but it '''must''' be the same end for the entire solution. (The end flipped can't be arbitrarily changed.)
Show both the initial, unsorted list and the final sorted list.
(Intermediate steps during sorting are optional.)
Optimizations are optional (but recommended).
;Related tasks:
*   [[Number reversal game]]
*   [[Topswops]]
;Also see:
*   Wikipedia article:   [[wp:Pancake sorting|pancake sorting]].
<br><br>