Sorting algorithms/Quicksort: Difference between revisions
Content added Content deleted
m (Added Io version.) |
|||
Line 639: | Line 639: | ||
IDL> print,qs([3,17,-5,12,99]) |
IDL> print,qs([3,17,-5,12,99]) |
||
-5 3 12 17 99 |
-5 3 12 17 99 |
||
=={{header|Io}}== |
|||
<lang io>List do( |
|||
quickSort := method( |
|||
if(size > 1) then( |
|||
pivot := at(size / 2 floor) |
|||
return select(x, x < pivot) quickSort appendSeq( |
|||
select(x, x == pivot) appendSeq(select(x, x > pivot) quickSort) |
|||
) |
|||
) else(return self) |
|||
) |
|||
quickSortInPlace := method( |
|||
copy(self getSlot("quickSort") performOn( |
|||
self, call sender, call message |
|||
)) |
|||
) |
|||
) |
|||
lst := list(5, -1, -4, 2, 9) |
|||
lst quickSort println # ==> list(-4, -1, 2, 5, 9) |
|||
lst quickSortInPlace println # ==> list(-4, -1, 2, 5, 9)</lang> |
|||
Another more low-level Quicksort implementation can be found in Io's [[http://github.com/stevedekorte/io/blob/master/samples/misc/qsort.io github ]] repository. |
|||
=={{header|J}}== |
=={{header|J}}== |
||
{{eff note|J|/:~}} |
{{eff note|J|/:~}} |