3 ms·
Let me fix that for you. qsort(){ local L=""; local G=""; [ $# -eq 1 ] && echo $1 && return; P=$1; shift;
by darkstar999 12y ago
Let me fix that for you.
qsort(){
local L="";
local G="";
[ $# -eq 1 ] && echo $1 && return;
P=$1;
shift;
for i in $@; do
[ $i -lt $P ] && L="$L $i" || G="$G $i";
done
[ -z "$L" ] || L=`qsort $L`;
[ -z "$G" ] || G=`qsort $G`;
echo "$L $P $G"
}
qsort $@
Looks more like 14 lines to me.
- deleted 12y ago[deleted]
- kazinator 12y agoAlso: what? No median-of-three pivot selection? # these lines replace "P=$1" line: local first=$1 eval local last=\${$#} eval local mid=\${$((($#+1)/2))} if [ $first -le $mid ] ; then if [ $mid -le $last ] ; then P=$mid elif [ $first -le $last ] ; then P=$last else P=$first fi else if [ $first -le $last ] ; then P=$first elif [ $mid -le $last ] ; then P=$last else P=$mid fi fi That little enhancement blows up the LOC quite a bit. :)
- kazinator 12y agoAlso, suppose we abstract the operators a little bit: if [ $x $LT $y ] ; ... If we set LT to "-lt" we get numeric comparison. Change it to "-ot" and we can order paths by modification timestamp. Set LT to "<" and obtain lexicographic sorting on strings.