Sorting algorithms/Quicksort: Difference between revisions
Content added Content deleted
Line 442: | Line 442: | ||
=={{header|UnixPipes}}== |
=={{header|UnixPipes}}== |
||
split() { |
|||
# though it looks imperative at first sight, the logic is actually |
|||
(pivot=$1; lc=$2; gc=$3; |
|||
# a pipeline split again and again into smaller ones and joined together. |
|||
while read n ; do |
|||
test $pivot -gt $n && echo $n > $lc || echo $n > $gc |
|||
⚫ | |||
} |
|||
qsort() { |
qsort() { |
||
lc="1.$1" ; gc="2.$1" |
|||
read pivot; test -n "$pivot" && ( |
|||
split $pivot >(cat >> $lc) >( cat >> $gc); |
|||
⚫ | |||
⚫ | |||
) |
|||
⚫ | |||
rm -f $lc $gc; |
|||
} |
} |
||
cat to.sort | qsort |
cat to.sort | qsort |