Sort stability: Difference between revisions

Content added Content deleted
m (→‎{{header|Go}}: update text for current library.)
(added sort by rowid to enforce a stable sort)
Line 330: Line 330:


=={{header|OpenEdge/Progress}}==
=={{header|OpenEdge/Progress}}==
The results can be forced to stable by ''additionally'' sorting on the ROWID of the record. If you leave the additional sort out the indexes on the temp-table can influence the result.
{{incorrect|OpenEdge/Progress|This is not enough as a particular sort might give a particular result whilst saying nothing about the stability '''in general'''.}}
The results are stable.
<lang progress>DEFINE TEMP-TABLE tt
<lang progress>DEFINE TEMP-TABLE tt
FIELD country AS CHAR FORMAT 'x(2)'
FIELD country AS CHAR FORMAT 'x(2)'
FIELD city AS CHAR FORMAT 'x(16)'
FIELD city AS CHAR FORMAT 'x(16)'
.
.

DEFINE VARIABLE cc AS CHARACTER EXTENT 2.


CREATE tt. ASSIGN tt.country = 'UK' tt.city = 'London'.
CREATE tt. ASSIGN tt.country = 'UK' tt.city = 'London'.
Line 342: Line 343:
CREATE tt. ASSIGN tt.country = 'UK' tt.city = 'Birmingham'.
CREATE tt. ASSIGN tt.country = 'UK' tt.city = 'Birmingham'.


cc[1] = 'by country~n~n'.
FOR EACH tt BY tt.country:
DISPLAY tt.country tt.city.
FOR EACH tt BY tt.country BY ROWID( tt ):
cc[1] = cc[1] + tt.country + '~t' + tt.city + '~n'.
END.
END.


cc[2] = 'by city~n~n'.
FOR EACH tt BY tt.city:
DISPLAY tt.country tt.city.
FOR EACH tt BY tt.city BY ROWID( tt ):
cc[2] = cc[2] + tt.country + '~t' + tt.city + '~n'.
END.</lang>
END.

MESSAGE
cc[1] SKIP(1) cc[2]
VIEW-AS ALERT-BOX.</lang>

'''Output:'''
<pre>---------------------------
Message
---------------------------
by country

UK London
UK Birmingham
US New York
US Birmingham


by city

US Birmingham
UK Birmingham
UK London
US New York
---------------------------
OK
---------------------------</pre>


=={{header|Oz}}==
=={{header|Oz}}==