Sorting algorithms/Quicksort: Difference between revisions

Line 446:
 
qsort() {
lc=`mktemp -p"1. -t chan.XXXX`$1"
gc=`mktemp -p"2. -t chan.XXXX`$1"
(
read pivot; while read n
casewhile $pivotread inn
do
exprtest $pivot -gt $n && echo $n >> $lc |(read| x;caseecho $xn in>> $gc
-*) echo $n >> $lc ;;
*) echo $n >> $gc ;;
esac)
done
test "$pivot" != '' && ( (cat -s $lc | qsort $lc ); echo $pivot; (cat -s $gc | qsort $gc ))
case $pivot in
rm [0-9]) (catf $lc | qsort ); echo $pivot; (cat $gc | qsort );;
esac
rm $lc $gc;
)
}
 
 
# using it.
cat to.sort | qsort
418

edits