Sorting algorithms/Bubble sort: Difference between revisions

Updated D entry
m (Added assumption to Standard ML solution)
(Updated D entry)
Line 714:
=={{header|D}}==
<lang d>import std.stdio, std.algorithm;
 
void bubbleSort(T)(T[] data) pure nothrow {
intauto itemCount = data.length;
bool hasChanged = false;
 
do {
hasChanged = false;
itemCount--;
foreach (immutable i; 0 .. itemCount)
if (data[i] > data[i + 1]) {
swap(data[i], data[i + 1]);
Line 729:
} while (hasChanged);
}
 
void main() {
auto array = [28, 44, 46, 24, 19, 2, 17, 11, 25, 4];
Line 735:
writeln(array);
}</lang>
{{out}}
Output:
<pre>[2, 4, 11, 17, 19, 24, 25, 28, 44, 46]</pre>