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
done)
}


qsort() {
qsort() {
lc="1.$1" ; gc="2.$1"
lc="1.$1" ; gc="2.$1"
read pivot; while read n ; do
read pivot; test -n "$pivot" && (
test $pivot -gt $n && echo $n >> $lc || echo $n >> $gc
split $pivot >(cat >> $lc) >( cat >> $gc);
(cat -s $lc | qsort $lc ) echo $pivot; (cat -s $gc | qsort $gc )
done
)
test -n "$pivot" && ( (cat -s $lc | qsort $lc ); echo $pivot; (cat -s $gc | qsort $gc ))
rm -f $lc $gc;
rm -f $lc $gc;
}
}



cat to.sort | qsort
cat to.sort | qsort