Sorting algorithms/Bubble sort: Difference between revisions

Add Draco
(Add Draco)
Line 2,106:
0 3 5 7 8 16 20 27 29 31 37 42 47 67 84 86
</pre>
 
=={{header|Draco}}==
<lang draco>/* Bubble sort an array of integers */
proc nonrec bubblesort([*] int a) void:
bool sorted;
int i, temp;
sorted := false;
while not sorted do
sorted := true;
for i from 1 upto dim(a,1)-1 do
if a[i-1] > a[i] then
sorted := false;
temp := a[i-1];
a[i-1] := a[i];
a[i] := temp
fi
od
od
corp
 
/* Test */
proc nonrec main() void:
int i;
[10] int a = (9, -5, 3, 3, 24, -16, 3, -120, 250, 17);
write("Before sorting: ");
for i from 0 upto 9 do write(a[i]:5) od;
writeln();
bubblesort(a);
write("After sorting: ");
for i from 0 upto 9 do write(a[i]:5) od
corp</lang>
{{out}}
<pre>Before sorting: 9 -5 3 3 24 -16 3 -120 250 17
After sorting: -120 -16 -5 3 3 3 9 17 24 250</pre>
 
=={{header|Dyalect}}==
2,099

edits