RE: stable sorting

new topic     » topic index » view thread      » older message » newer message

> From: Juergen Luethje [mailto:eu.lue at gmx.de]

> The following code (modified after 'csort.ex') does *not* perform a
> stable sorting.
> 
> ----------=----------=----------=----------=----- begin of code
> include sort.e
> 
> constant MARK = 2
> constant statistics = {
>    {"Doe", 3},
>    {"Einstein", 1},
>    {"Goldberg", 1},
>    {"Irving", 4},
>    {"Jones", 3},
>    {"Miller", 2},
>    {"Neuman", 2},
>    {"Petersen", 4},
>    {"Smith", 2},
>    {"Zander", 5}
> }
> 
> function compare_mark (sequence a, sequence b)
>    -- Compare two sequences (records) according to MARK.
>    return compare(a[MARK], b[MARK])
> end function

try:

function compare_mark (sequence a, sequence b)
   integer c
   -- Compare two sequences (records) according to MARK.
   c = compare(a[MARK], b[MARK])
   if c then
      return c
   end if
   return compare(a[1],b[1])
end function


Matt Lewis

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu