Anonymous user
Sort stability: Difference between revisions
→{{header|Oz}}: Added example
No edit summary |
(→{{header|Oz}}: Added example) |
||
Line 74:
Oz' [http://www.mozart-oz.org/home/doc/base/list.html#label295 Sort] function is not guaranteed to be stable in the documentation.
However, internally it uses
Example:
<lang oz>declare
Cities = ['UK'#'London'
'US'#'New York'
'US'#'Birmingham'
'UK'#'Birmingham']
in
%% sort by city; stable because '=<' is reflexiv
{Show {Sort Cities fun {$ A B} A.2 =< B.2 end}}
%% sort by country; NOT stable because '<' is not reflexiv
{Show {Sort Cities fun {$ A B} A.1 < B.1 end}}</lang>
=={{header|Perl}}==
|