Quicksort in 3 lines of shell
github.com
Quicksort in 3 lines of shell
1–10 of 20 posts
Re: Quicksort in 3 lines of shell
#2Reminds me http://bash.org/?464385
Re: Quicksort in 3 lines of shell
#3> L=`qsort $L`
POSIX has standardized $(qsort $L) syntax since 1990. It's okay to use it now.
Re: Quicksort in 3 lines of shell
#4Maybe we should all learn to always prepend "Pseudo" to these "quicksorts"?
Re: Quicksort in 3 lines of shell
#5Hey, check out this 1-liner HTTP server!
:%s/\n/ /g
Re: Quicksort in 3 lines of shell
#6A couple of characters less in C ( I didn't count whitespace in both ):
void qs( int* a , int z )
{
if(z > 1){ ; int p = a[z/2], s = 0, e = z-1, t; while(s for(;a[s] p; e--); if(s a[s++] = a[e]; a[e--] = t; } } qs( a , e+1 ); qs( a+s , z-s ); }
}
Re: Quicksort in 3 lines of shell
#7[deleted]
Re: Quicksort in 3 lines of shell
#8Let 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.Re: Quicksort in 3 lines of shell
#9It's not 3 commands so I'm sure you can get it down to 1 line.
Re: Quicksort in 3 lines of shell
#10Maybe we should all learn to always prepend "Pseudo" to these "quicksorts"?
Is it not really a quicksort?