K
kokolo
I won't spam on this subject any more. I ckecked out a little and realizedI found an implementation without sub-arrays:
http://www.thescripts.com/forum/thread49795.html
changedit so it works and tried it for 99999 elements.
It did it in13 seconds while my code does it in 14.
How quick it can get at all?
kokolo
that the code from the link above is
just a re-written C-code from
http://linux.wku.edu/~lamonml/algor/sort/quick.html
It doesn't have any Perl flavor and is much harder to read.
Yes, it's faster but only 1 sec for 100000 elements (13 to 14). I like this
one much more for the flavor (push, pop) and readibility:
_____________________________________________________-
print "Enter the number of elements to sort: \n";
chomp($size=<STDIN>);
foreach (1..$size) {push @array,int(rand(1000))}
$start=time();
@array= qs(@array);
#print "The sorted array:\n @array \n";
print "$size elementsQuickSorted in ,",time()-$start," seconds.\n";
sub qs {
my @array=@_;
my $pivot=$#array;
my @left;
my @right;
for ($i=0;$i<$pivot;$i++){
if ($red[$i]<=$red[$pivot]){ unshift @left,$red[$i]}
else { push @right,$red[$i]}
}
if ($#left>0){@left=qs(@left)}
if ($#right>0){@right=qs(@right)}
push @left,($red[$pivot],@right);
return @left;
}
____________________________________________________________________________
___________
I appreciate all advices, those about referencing in particular but I'd
really appreciate if somebody
can help me find how quick Perl can get with quicksort.
C does 100000 elements in less than a second. I'm aware Perl has to be
slower and that there are builtins,etc. but I'm not asking for general
advices.
C-like code does it in 13. I believe this is far from Perl limit.
kokolo