1
0
Fork 0
mirror of synced 2025-09-23 12:18:44 +00:00
ZoKrates/zokrates_cli/examples/book/bubblesort.zok
2022-04-06 20:23:58 +02:00

20 lines
417 B
Text

def swap(u32 a, u32 b, bool c) -> (u32, u32) {
u32 a_prime = c ? b : a;
b = c ? a : b;
return a_prime, b;
}
def bubblesort<N>(u32[N] a) -> u32[N] {
for u32 i in 0..(N-1) {
for u32 j in 0..(N-1-i) {
bool need_swap = a[j + 1] < a[j];
a[j], a[j + 1] = swap(a[j], a[j + 1], need_swap);
}
}
return a;
}
def main(u32[10] a) -> u32[10] {
return bubblesort(a);
}