Sorting algorithms/Stooge sort: Difference between revisions
Content deleted Content added
m →{{header|REXX}}: changed a comment in the REXX section header. |
No edit summary |
||
Line 1,547: | Line 1,547: | ||
element 18 after sort: 48 |
element 18 after sort: 48 |
||
element 19 after sort: 54 |
element 19 after sort: 54 |
||
</pre> |
|||
=={{header|Ring}}== |
|||
<lang ring> |
|||
test = [4, 65, 2, -31, 0, 99, 2, 83, 782, 1] |
|||
stoogeSort(test, 1, len(test)) |
|||
for i = 1 to 10 |
|||
see "" + test[i] + " " |
|||
next |
|||
see nl |
|||
func stoogeSort list, i, j |
|||
if list[j] < list[i] |
|||
temp = list[i] |
|||
list[i] = list[j] |
|||
list[j] = temp ok |
|||
if j - i > 1 |
|||
t = (j - i + 1)/3 |
|||
stoogeSort(list, i, j-t) |
|||
stoogeSort(list, i+t, j) |
|||
stoogeSort(list, i, j-t) ok |
|||
return list |
|||
</lang> |
|||
Output: |
|||
<pre> |
|||
-31 0 1 2 2 4 65 83 99 782 |
|||
</pre> |
</pre> |
||