Sorting algorithms/Pancake sort: Difference between revisions

Added 11l
(→‎{{header|UNIX Shell}}: Add implementation)
(Added 11l)
Line 27:
*   Wikipedia article:   [[wp:Pancake sorting|pancake sorting]].
<br><br>
 
=={{header|11l}}==
{{trans|Python}}
 
<lang 11l>V tutor = 1B
 
F pancakesort(&data)
I data.len <= 1
R
I :tutor
print()
L(size) (data.len .< 1).step(-1)
V maxindex = max(0 .< size, key' x -> @data[x])
I maxindex + 1 != size
I maxindex != 0
I :tutor
print(‘With: #. doflip #.’.format(data.map(x -> String(x)).join(‘ ’), maxindex + 1))
data.reverse_range(0 .< maxindex + 1)
I :tutor
print(‘With: #. doflip #.’.format(data.map(x -> String(x)).join(‘ ’), size))
data.reverse_range(0 .< size)
I :tutor
print()
 
V data = ‘6 7 2 1 8 9 5 3 4’.split(‘ ’)
print(‘Original List: ’data.join(‘ ’))
pancakesort(&data)
print(‘Pancake Sorted List: ’data.join(‘ ’))</lang>
 
{{out}}
<pre>
Original List: 6 7 2 1 8 9 5 3 4
 
With: 6 7 2 1 8 9 5 3 4 doflip 6
With: 9 8 1 2 7 6 5 3 4 doflip 9
With: 4 3 5 6 7 2 1 8 9 doflip 5
With: 7 6 5 3 4 2 1 8 9 doflip 7
With: 1 2 4 3 5 6 7 8 9 doflip 3
With: 4 2 1 3 5 6 7 8 9 doflip 4
With: 3 1 2 4 5 6 7 8 9 doflip 3
With: 2 1 3 4 5 6 7 8 9 doflip 2
 
Pancake Sorted List: 1 2 3 4 5 6 7 8 9
</pre>
 
=={{header|AArch64 Assembly}}==
Line 265 ⟶ 309:
Table sorted.
</pre>
 
=={{header|Ada}}==
 
1,480

edits