RE: stable sorting
> 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
|
Not Categorized, Please Help
|
|