RE: stable sorting

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

Andy Serpa wrote:
> 
> Matthew Lewis wrote:
> > 
> > > 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
> > 
> > 
> Here's what I do:
> 
> ----------------------
> include sort.e
> 
> -- Don't call this function directly, see below
> integer sort_i

Messed up.  That should be "object sort_i"

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

Search



Quick Links

User menu

Not signed in.

Misc Menu