Sort stability: Difference between revisions
Content added Content deleted
Alextretyak (talk | contribs) (Added 11l) |
|||
Line 1,138: | Line 1,138: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
Default Nim sort in the algorithm module is stable. |
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}}== |
=={{header|OCaml}}== |