Sort stability: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Added Ada)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 128:
=={{header|C}}==
There is no built-in function in C ''language''. <code>stdlib</code> which comes with any C ''implementation'' is required to provide a [[wp:Qsort|<code>qsort()</code>]] routine that can sort arbitrary datatypes. Although the sorting algorithm is not specified, most (all?) implementions use a combined quicksort/insertion sort method for efficiency. Quicksort is by nature unstable.
 
=={{header|C++}}==
C++ standard library's [http://www.sgi.com/tech/stl/sort.html std::sort()] function is not guaranteed stable. The stable analog of it is the [http://www.sgi.com/tech/stl/stable_sort.html std::stable_sort()] function. In addition, [http://www.sgi.com/tech/stl/List.html std::list]'s <tt>sort()</tt> method is guaranteed stable.
 
=={{header|C sharp|C#}}==
The .NET library documentation for <tt>Array.Sort()</tt> says that it uses quicksort and is unstable.[http://msdn.microsoft.com/en-us/library/kwx6zbd4.aspx#remarksToggle]
 
=={{header|C++}}==
C++ standard library's [http://www.sgi.com/tech/stl/sort.html std::sort()] function is not guaranteed stable. The stable analog of it is the [http://www.sgi.com/tech/stl/stable_sort.html std::stable_sort()] function. In addition, [http://www.sgi.com/tech/stl/List.html std::list]'s <tt>sort()</tt> method is guaranteed stable.
 
=={{header|Clojure}}==
Line 166:
 
<em>Unstable</em>, <em>stable</em> and <em>semistable</em> (in algorithms that partition ranges in two, <em>semistable</em> preserves stability on just the left of the partition point) are supported.
 
=={{header|Déjà Vu}}==
The included sorting algorithm, <code>sort</code>, is stable.
Line 199 ⟶ 200:
=={{header|Erlang}}==
The function lists:sort/1 is not documented as stable. The function lists:keysort/2 is documented as stable.
 
=={{header|F_Sharp|F#}}==
[http://msdn.microsoft.com/en-us/library/ee370375.aspx <code>Array.sort</code>] is not stable.
[http://msdn.microsoft.com/en-us/library/ee370323.aspx <code>List.sort</code>] and [http://msdn.microsoft.com/en-us/library/ee353483.aspx <code>Seq.sort</code>] are stable.
 
=={{header|Factor}}==
Line 205 ⟶ 210:
=={{header|Fortran}}==
The language does not offer an in-built sort facility. Numerous libraries exist, which may or may not have documentation on their sort routine's stability.
 
=={{header|F_Sharp|F#}}==
[http://msdn.microsoft.com/en-us/library/ee370375.aspx <code>Array.sort</code>] is not stable.
[http://msdn.microsoft.com/en-us/library/ee370323.aspx <code>List.sort</code>] and [http://msdn.microsoft.com/en-us/library/ee353483.aspx <code>Seq.sort</code>] are stable.
 
=={{header|GAP}}==
Line 924 ⟶ 925:
The stability of Perl's in-built [http://perldoc.perl.org/functions/sort.html sort] function is version-dependent. If you want to guarantee a stable sort from it, you should use the following [http://perldoc.perl.org/sort.html sort pragma]:
<lang perl>use sort 'stable';</lang>
 
=={{header|Perl 6}}==
The [http://perlcabal.org/syn/S32/Containers.html#sort sort] built-in (available as sub and method) is stable.
 
Short demonstration for sorting only on the second item of each array:
<lang perl6>use v6;
my @cities =
['UK', 'London'],
['US', 'New York'],
['US', 'Birmingham'],
['UK', 'Birmingham'],
;
 
.say for @cities.sort: { .[1] };</lang>
 
=={{header|Phix}}==
Line 1,045 ⟶ 1,032:
;; ("UK" "London") ("US" "New York"))
</lang>
 
=={{header|Perl 6Raku}}==
(formerly Perl 6)
The [http://perlcabal.org/syn/S32/Containers.html#sort sort] built-in (available as sub and method) is stable.
 
Short demonstration for sorting only on the second item of each array:
<lang perl6>use v6;
my @cities =
['UK', 'London'],
['US', 'New York'],
['US', 'Birmingham'],
['UK', 'Birmingham'],
;
 
.say for @cities.sort: { .[1] };</lang>
 
=={{header|REBOL}}==
10,333

edits