Sorting algorithms/Quicksort: Difference between revisions

Content added Content deleted
m (→‎{{header|Fortran}}: added syntax highlighting)
m (→‎{{header|Tailspin}}: Neater expression)
Line 9,509: Line 9,509:
def last: $(2);
def last: $(2);
def pivot: $@quicksort($first);
def pivot: $@quicksort($first);
[ $first + 1, $last ] -> #
@: $(1) + 1;
$(2) -> #


when <?($(2) <..~$(1)>)> do
when <..~$@> do
def limit: $(2);
def limit: $;
@quicksort($first): $@quicksort($limit);
@quicksort($first): $@quicksort($limit);
@quicksort($limit): $pivot;
@quicksort($limit): $pivot;
Line 9,518: Line 9,519:
[ $limit + 1, $last ] !
[ $limit + 1, $last ] !


when <?($@quicksort($(2)) <$pivot~..>)> do
when <?($@quicksort($) <$pivot~..>)> do
[ $(1), $(2) - 1] -> #
$ - 1 -> #


when <?($@quicksort($(1)) <..$pivot>)> do
when <?($@quicksort($@) <..$pivot>)> do
[ $(1) + 1, $(2)] -> #
@: $@ + 1; $ -> #


otherwise
otherwise
def temp: $@quicksort($(1));
def temp: $@quicksort($@);
@quicksort($(1)): $@quicksort($(2));
@quicksort($@): $@quicksort($);
@quicksort($(2)): $temp;
@quicksort($): $temp;
[ $(1) + 1, $(2) - 1] -> #
@: $@ + 1; $ - 1 -> #
end partial
end partial
@: $;
@: $;