Jump to content

Sorting algorithms/Quicksort: Difference between revisions

Line 442:
 
=={{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() {
lc="1.$1" ; gc="2.$1"
read pivot; while readtest -n ;"$pivot" && do(
testsplit $pivot -gt $n && echo $n>(cat >> $lc) ||>( echo $ncat >> $gc);
test -n "$pivot" && ( (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;
}
 
 
cat to.sort | qsort
418

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.