Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Looking for numeric sort (was Simon Davey)

by Anonymous Monk
on Aug 19, 2002 at 09:22 UTC ( [id://191116]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Greetings programmers, I am looking for a module which implements a fast integer sorting algorithm for large lists like the Shell (as in the oil company) sort or the Quick sort. Any pointers appreciated! Thank you all.

Edit kudra, 2002-08-19 Changed title

  • Comment on Looking for numeric sort (was Simon Davey)

Replies are listed 'Best First'.
Re: Fast sort
by Aristotle (Chancellor) on Aug 19, 2002 at 10:03 UTC
    The sort builtin is implemented using Quicksort up to Perl 5.6.1; in 5.8 it has been switched to a stable Mergesort, and using physgreg's idiom will do what you want faster than any module written in Perl itself is ever likely to achieve.

    Makeshifts last the longest.

Re: Simon Davey
by physgreg (Scribe) on Aug 19, 2002 at 09:44 UTC
    The internal perl sort command can be used to sort numerically:
    @sorted_list = sort {$a<=>$b} @unsorted_list
    The <=> operator returns 0 if the two numbers are equal, -1 if $a<$b and 1 if $a>$b. Hope that helps.
Re: Simon Davey
by Abigail-II (Bishop) on Aug 19, 2002 at 11:08 UTC
    Shell sort wasn't named after the oil company, but after mister Shell.

    Abigail

      It's very similar to the monte sort, but works with peas instead of cards. But it's still limited to only three objects.

      --
      Tommy
      Too stupid to live.
      Too stubborn to die.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-18 22:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found