From 6f52f8080529fd1db694d4322c1a1da5f1361537 Mon Sep 17 00:00:00 2001 From: cozis Date: Tue, 8 Mar 2022 21:49:31 +0100 Subject: [PATCH] new format convention --- samples/bubble_sort.noja | 46 +++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/samples/bubble_sort.noja b/samples/bubble_sort.noja index c380fb5..909be0f 100644 --- a/samples/bubble_sort.noja +++ b/samples/bubble_sort.noja @@ -1,43 +1,37 @@ -fun copy(L) -{ +fun copy(L) { + L2 = []; i = 0; - while i < count(L): - { - L2[i] = L[i]; - i = i + 1; - } + while i < count(L): { + L2[i] = L[i]; + i = i + 1; + } return L2; } -fun bubble_sort(L, less) -{ +fun bubble_sort(L, less) { if less == none: fun less(a, b) return a < b; L = copy(L); - do - { - swapped = false; + 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; + 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; }