Sorting algorithms/Bubble sort: Difference between revisions

Content added Content deleted
(Added bubble sort for EDSAC)
Line 5,480: Line 5,480:
{{out}}
{{out}}
<pre><140,212,247,270,315,362,449,532,567,677></pre>
<pre><140,212,247,270,315,362,449,532,567,677></pre>

=={{header|Vala}}==
<lang vala>void swap(int[] array, int i1, int i2) {
if (array[i1] == array[i2])
return;
var tmp = array[i1];
array[i1] = array[i2];
array[i2] = tmp;
}

void bubble_sort(int[] array) {
bool flag = true;
int j = array.length;
while(flag) {
flag = false;
for (int i = 1; i < j; i++) {
if (array[i] < array[i - 1]) {
swap(array, i - 1, i);
flag = true;
}
}
j--;
}
}

void main() {
int[] array = {5, -1, 101, -4, 0, 1, 8, 6, 2, 3};
bubble_sort(array);
foreach (int i in array) {
stdout.printf("%d ", i);
}
}</lang>
{{out}}
<pre>
-4 -1 0 1 2 3 5 6 8 101
</pre>


=={{header|VBA}}==
=={{header|VBA}}==
Line 5,513: Line 5,549:
After:
After:
-31, 0, 1, 2, 2, 4, 13, 15, 19, 782, alfa, beta, delta, gamma</pre>
-31, 0, 1, 2, 2, 4, 13, 15, 19, 782, alfa, beta, delta, gamma</pre>

=={{header|VBScript}}==
=={{header|VBScript}}==
Doing the decr and incr thing is superfluous, really. I just had stumbled over the byref thing for <code>swap</code> and wanted to see where else it would work.
Doing the decr and incr thing is superfluous, really. I just had stumbled over the byref thing for <code>swap</code> and wanted to see where else it would work.