|
|
Line 214: |
Line 214: |
|
|
|
|
|
{{works with|DMD|1.025}} |
|
{{works with|DMD|1.025}} |
|
|
<d> |
|
import std.stdio;
|
|
import std.stdio; |
|
|
|
⚫ |
void bubbleSort(T)(T[] array) { |
|
|
int itemCount = array.length; |
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
for (int index = 0; index < itemCount; index++) { |
|
⚫ |
if (array[index] > array[index + 1]) { |
|
⚫ |
|
|
⚫ |
array[index] = array[index + 1]; |
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
|
|
|
⚫ |
|
|
⚫ |
auto array = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1].dup; |
|
|
|
|
|
|
⚫ |
void bubbleSort(T)(T[] array) { |
⚫ |
// member function invocation syntax for arrays |
|
|
array.bubbleSort(); |
|
int itemCount = array.length; |
|
⚫ |
|
⚫ |
foreach (index, value; array) |
|
|
⚫ |
|
⚫ |
writefln("array[%d] = %d", index, value); |
|
|
⚫ |
|
⚫ |
|
|
|
⚫ |
|
|
⚫ |
for (int index = 0; index < itemCount; index++) { |
|
⚫ |
if (array[index] > array[index + 1]) { |
|
⚫ |
|
|
⚫ |
array[index] = array[index + 1]; |
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
|
|
|
⚫ |
|
|
⚫ |
auto array = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1].dup; |
|
|
|
|
⚫ |
// member function invocation syntax for arrays |
|
|
array.bubbleSort(); |
|
⚫ |
foreach (index, value; array) |
|
⚫ |
writefln("array[%d] = %d", index, value); |
|
⚫ |
|
|
|
</d> |
|
|
|
|
|
=={{header|E}}== |
|
=={{header|E}}== |