Sorting algorithms/Quicksort: Difference between revisions
Content added Content deleted
Line 446: | Line 446: | ||
qsort() { |
qsort() { |
||
lc= |
lc="1.$1" |
||
gc= |
gc="2.$1" |
||
( |
( |
||
read pivot; |
read pivot; |
||
⚫ | |||
do |
do |
||
test $pivot -gt $n && echo $n >> $lc || echo $n >> $gc |
|||
-*) echo $n >> $lc ;; |
|||
*) echo $n >> $gc ;; |
|||
esac) |
|||
done |
done |
||
test "$pivot" != '' && ( (cat -s $lc | qsort $lc ); echo $pivot; (cat -s $gc | qsort $gc )) |
|||
⚫ | |||
rm -f $lc $gc; |
|||
esac |
|||
rm $lc $gc; |
|||
) |
) |
||
} |
} |
||
# using it. |
|||
cat to.sort | qsort |
cat to.sort | qsort |