Anonymous user
Sorting algorithms/Bubble sort: Difference between revisions
D code ported to D2
(D code ported to D2) |
|||
Line 605:
=={{header|D}}==
<lang d>import std.stdio, std.algorithm;▼
▲<lang d>import std.stdio;
bool hasChanged = false;▼
▲void bubbleSort(T)(T[] array) {
▲ int itemCount = array.length;
▲ bool hasChanged;
do {
hasChanged = false;
itemCount--;
if (
hasChanged = true;
}
} while (hasChanged);
}
void main() {
auto array = [
array.bubbleSort();
}</lang>
Output:
<pre>[2, 4, 11, 17, 19, 24, 25, 28, 44, 46]</pre>
=={{header|E}}==
|