renamed samples to examples

This commit is contained in:
cozis
2022-03-13 15:40:10 +01:00
parent bf25e0f1a9
commit eae8536e3b
11 changed files with 0 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
fun copy(L) {
L2 = [];
i = 0;
while i < count(L): {
L2[i] = L[i];
i = i + 1;
}
return L2;
}
fun bubble_sort(L, less) {
if less == none:
fun less(a, b) return a < b;
L = copy(L);
do {
swapped = false;
i = 0;
while i < count(L)-1 and not swapped: {
if less(L[i+1], L[i]): {
swapped = true;
tmp = L[i+1];
L[i+1] = L[i];
L[i] = tmp;
}
i = i + 1;
}
} while swapped;
return L;
}
print(bubble_sort([3, 2, 1, 6, 0-2]));