Sort stability: Difference between revisions

No edit summary
(→‎{{header|Tcl}}: added zkl)
Line 1,002:
=={{header|Tcl}}==
Tcl's built-in [http://www.tcl.tk/man/tcl8.4/TclCmd/lsort.htm <code>lsort</code>] command implements a stable sort. It has been guaranteed to be stable since Tcl 8.0. Internally, it uses the mergesort algorithm.
 
=={{header|zkl}}==
zkl's sort methods don't mention stability or columns, they are comparison based.
<lang zkl>fcn sortByColumn(list,col)
{ list.sort('wrap(city1,city2){ city1[col]<city2[col] }) }</lang>
<lang zkl>cities:=List(
T("UK", "London"), T("US", "New York"),
T("US", "Birmingham"),T("UK", "Birmingham"), );
sortByColumn(cities,0).concat("\n").println("\n------");
sortByColumn(cities,1).concat("\n").println();</lang>
{{out}}
<pre>
L("UK","London")
L("UK","Birmingham")
L("US","New York")
L("US","Birmingham")
------
L("UK","Birmingham")
L("US","Birmingham")
L("UK","London")
L("US","New York")
</pre>
Anonymous user