Sort stability: Difference between revisions

(Added 11l)
Line 1,138:
=={{header|Nim}}==
Default Nim sort in the algorithm module is stable.
<lang Nim>import algorithm
 
const Records = [(country: "UK", city: "London"),
(country: "US", city: "New York"),
(country: "US", city: "Birmingham"),
(country: "UK", city: "Birmingham")]
 
echo "Original order:"
for record in Records:
echo record.country, " ", record.city
echo()
 
echo "Sorted by city name:"
for record in Records.sortedByIt(it.city):
echo record.country, " ", record.city
echo()
 
echo "Sorted by country name:"
for record in Records.sortedByIt(it.country):
echo record.country, " ", record.city</lang>
 
{{out}}
<pre>Original order:
UK London
US New York
US Birmingham
UK Birmingham
 
Sorted by city name:
US Birmingham
UK Birmingham
UK London
US New York
 
Sorted by country name:
UK London
UK Birmingham
US New York
US Birmingham</pre>
 
=={{header|OCaml}}==
Anonymous user