Sorting algorithms/Quicksort: Difference between revisions
Content added Content deleted
(JavaScript) |
|||
Line 440: | Line 440: | ||
</pre> |
</pre> |
||
Original source: [http://seed7.sourceforge.net/algorith/sorting.htm#quickSort] |
Original source: [http://seed7.sourceforge.net/algorith/sorting.htm#quickSort] |
||
=={{header|UnixPipes}}== |
|||
# though it looks imperative at first sight, the logic is actually |
|||
# a pipeline split again and again into smaller ones and joined together. |
|||
qsort() { |
|||
lc=`mktemp -p. -t chan.XXXX` |
|||
gc=`mktemp -p. -t chan.XXXX` |
|||
( |
|||
read pivot; while read n |
|||
do |
|||
expr $pivot - $n |(read x;case $x in |
|||
-*) echo $n >> $lc ;; |
|||
*) echo $n >> $gc ;; |
|||
esac) |
|||
done |
|||
case $pivot in |
|||
[0-9]) (cat $lc | qsort ); echo $pivot; (cat $gc | qsort );; |
|||
esac |
|||
rm $lc $gc; |
|||
) |
|||
} |
|||
# using it. |
|||
cat to.sort | qsort |