updated code sample in the readme

This commit is contained in:
cozis
2022-08-15 04:16:30 +02:00
parent 6bd60bc84a
commit 8cac46440b
3 changed files with 47 additions and 28 deletions
+19 -15
View File
@@ -21,25 +21,29 @@ Here's an example of a noja program that orders the items in list using a bubble
```
L = [3, 2, 1];
do {
swapped = false;
fun swap(a: int, b: int)
return b, a;
i = 0;
while i < count(L)-1 and not swapped: {
fun order(L: List) {
if L[i+1] < L[i]: {
swapped = true;
tmp = L[i+1];
L[i+1] = L[i];
L[i] = tmp;
do {
swapped = false;
i = 0;
while i < count(L)-1 and not swapped: {
swapped = L[i+1] < L[i];
if swapped:
L[i], L[i+1] = swap(L[i], L[i+1]);
i = i+1;
}
i = i + 1;
}
} while swapped;
} while swapped;
}
print(L, '\n'); # Outputs [1, 2, 3]
print(L, '\n'); # [3, 2, 1]
order(L);
print(L, '\n'); # [1, 2, 3]
```
## Implementation Overview