Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Numeric sorting WITHOUT <=>

by jandrew (Hermit)
on Oct 09, 2012 at 22:53 UTC ( #998098=note: print w/ replies, xml ) Need Help??


in reply to Numeric sorting WITHOUT <=>

I think an insertion sort using splice might work

Homework Spoiler -
use Modern::Perl; use Smart::Comments; my %jetsons = ( 7 => 'Judy', 10 => 'Jane', 11 => 'George', 2 => 'Elroy', 100=> 'Rosey', 1 => 'Astro', 19 => 'Mr. Spacely', 22 => 'Mr. Cogswell'); my @result = (); for my $key ( keys %jetsons ){ my $x = 0; CHECKLIST: for my $value ( @result ){ if( $value > $key ){ last CHECKLIST; }else{ $x++; } } splice( @result, $x, 0, $key ); } ### @result

Returns

### @result: [ ### 1, ### 2, ### 7, ### 10, ### 11, ### 19, ### 22, ### 100 ### ]


Comment on Re: Numeric sorting WITHOUT <=>
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://998098]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (12)
As of 2015-07-06 15:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (77 votes), past polls