Anonymous user
Sorting algorithms/Bubble sort: Difference between revisions
fix bugs and nicer implementation
(fix bugs and nicer implementation) |
|||
Line 1,062:
=={{header|D}}==
<lang d>import std.stdio, std.algorithm : swap;
{
foreach_reverse (n; 0 .. data.length)
{
itemCount--;▼
if (data[i] > data[i + 1]) {
swap(data[i], data[i + 1]);
}
}
return data;
}
void main() {
auto array = [28, 44, 46, 24, 19, 2, 17, 11, 25, 4];
writeln(array.bubbleSort());
}</lang>
{{out}}
<pre>[2, 4, 11, 17, 19, 24, 25, 28, 44, 46]</pre>
=={{header|Dart}}==
|