in reply to Re: Fastest way to sort a list of integers into 0,1,2,3,-3,-2,-1
in thread Fastest way to sort a list of integers into 0,1,2,3,-3,-2,-1
I think your second version will be very slow if there are only negative numbers... ;) My version below is reasonably fast if there is no zero in the input, otherwise it fails:
hdb => sub { my @list = @input; @list = sort{$a*$b>0?$a<=>$b:$b<=>$a} @list; Compare(\@list,\@output) or die "@list" if DO_CHECK; },
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Fastest way to sort a list of integers into 0,1,2,3,-3,-2,-1
by Discipulus (Canon) on Feb 05, 2019 at 20:48 UTC | |
|
Re^3: Fastest way to sort a list of integers into 0,1,2,3,-3,-2,-1
by Tux (Canon) on Feb 06, 2019 at 10:58 UTC | |
by hdb (Monsignor) on Feb 06, 2019 at 11:13 UTC |