Anonymous user
Sorting algorithms/Bubble sort: Difference between revisions
→{{header|D}}
Line 214:
{{works with|DMD|1.025}}
<d>
void bubbleSort(T)(T[] array) {▼
bool hasChanged;▼
do {▼
hasChanged = false;▼
itemCount--;▼
for (int index = 0; index < itemCount; index++) {▼
if (array[index] > array[index + 1]) {▼
T temp = array[index];▼
array[index] = array[index + 1];▼
array[index + 1] = temp;▼
hasChanged = true;▼
}▼
}▼
} while (hasChanged);▼
}▼
void main() {▼
auto array = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1].dup;▼
// member function invocation syntax for arrays▼
int itemCount = array.
foreach (index, value; array)▼
writefln("array[%d] = %d", index, value);▼
}▼
array.bubbleSort();
</d>
=={{header|E}}==
|