Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,31 @@
|
|||
/* 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue