Jump to content

Sorting algorithms/Pancake sort: Difference between revisions

(Added Tailspin solution)
Line 3,553:
</pre>
As you can see, it took 12 flips.
 
=={{header|Transd}}==
<lang scheme>
#lang transd
 
MainModule: {
vint: [ 9, 0, 5, 10, 3, -3, -1, 8, -7, -4, -2, -6, 2, 4, 6, -10, 7, -8, -5, 1, -9],
_start: (λ (with n (- (size vint) 1) m 0
(textout vint "\n")
(while n
(= m (max-element-idx vint Range(0 (+ n 1))))
(if (neq m n)
(if m (reverse vint Range(0 (+ m 1))))
(reverse vint Range(0 (+ n 1))))
(-= n 1)
)
(textout vint "\n")
))
}</lang>{{out}}
<pre>
[9, 0, 5, 10, 3, -3, -1, 8, -7, -4, -2, -6, 2, 4, 6, -10, 7, -8, -5, 1, -9]
[-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
</pre>
 
=={{header|uBasic/4tH}}==
111

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.