Sorting algorithms/Quicksort: Difference between revisions

m
(→‎{{header|UnixPipes}}: slightly more parallel and hence faster)
Line 443:
=={{header|UnixPipes}}==
{{works with|Zsh}}
 
(a race condition seems to happen in bash when using cat -s instead of using the sequential print)
split() {
(pivot=$1;while read n lc=$2; gc=$3;do
test $pivot1 -gt $n && echo $n > $lc2 || echo $n > $gc3
while read n ; do
done)
test $pivot -gt $n && echo $n > $lc || echo $n > $gc
done)
}
 
qsort() {
read lc="1.$1" p; gc=test -n "2.$1p" && (
read pivot; test -n lc="1.$pivot1"; && (gc="2.$1"
split $pivotp >(>>$lc) >(>>$gc);
cat -s <(cat -s $lc|qsort $lc) <(echo $pivotp) <(cat -s $gc|qsort $gc)
rm -f $lc $gc;
)
rm -f $lc $gc;
}
 
418

edits