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

Re: The Effect of sort on Equal Items

by Zaxo (Archbishop)
on Oct 03, 2002 at 04:39 UTC ( #202441=note: print w/replies, xml ) Need Help??


in reply to The Effect of sort on Equal Items

To add to BrowserUK's answer, mergesort is stable, producing the original order for items that compare equal. Quicksort is not stable, the sorted order is scrambled for equal items.

In the perl 5.8.0 source tree, the sort algorithm is found in pp_sort.c. That file has unusually good comments in it. Here is the meat of perl's top level sort function, Perl_sortsv():

hints = SORTHINTS(hintsv); if (hints & HINT_SORT_QUICKSORT) { sortsvp = S_qsortsv; } else { /* The default as of 5.8.0 is mergesort */ sortsvp = S_mergesortsv; } sortsvp(aTHX_ array, nmemb, cmp);

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: The Effect of sort on Equal Items
by Dr. Mu (Hermit) on Oct 03, 2002 at 05:21 UTC
    Thanks to both! Yikes! Looks like that "margin note" is gonna hafta be a link. ;-)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2021-01-28 15:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?