1
0
Fork 0
mirror of synced 2025-09-24 04:40:05 +00:00
ZoKrates/zokrates_cli/examples/book/bubblesort.zok
2021-06-01 13:35:44 +01:00

16 lines
401 B
Text

def swap(u32 a, u32 b, bool c) -> (u32, u32):
u32 a_prime = if c then b else a fi
b = if c then a else b fi
return a_prime, b
def bubblesort<N>(u32[N] a) -> u32[N]:
for u32 i in 0..(N-1) do
for u32 j in 0..(N-1-i) do
bool need_swap = a[j + 1] < a[j]
a[j], a[j + 1] = swap(a[j], a[j + 1], need_swap)
endfor
endfor
return a
def main(u32[10] a) -> u32[10]:
return bubblesort(a)