Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions bubblesort/build/main.aleo
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,21 @@ function bubble_sort:
output r61 as u32.private;
output r46 as u32.private;
output r28 as u32.private;

closure is_sorted:
input r0 as [u32; 8u32];
gt r0[0u32] r0[1u32] into r1;
gt r0[1u32] r0[2u32] into r2;
gt r0[2u32] r0[3u32] into r3;
gt r0[3u32] r0[4u32] into r4;
gt r0[4u32] r0[5u32] into r5;
gt r0[5u32] r0[6u32] into r6;
gt r0[6u32] r0[7u32] into r7;
ternary r7 false true into r8;
ternary r6 false r8 into r9;
ternary r5 false r9 into r10;
ternary r4 false r10 into r11;
ternary r3 false r11 into r12;
ternary r2 false r12 into r13;
ternary r1 false r13 into r14;
output r14 as boolean;
11 changes: 11 additions & 0 deletions bubblesort/src/main.leo
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ program bubblesort.aleo {
// Note that the implementation below uses tuples instead of arrays.
// The implementation also manually unrolls the loop.

function is_sorted(arr: [u32; 8]) -> bool {
for i: u32 in 0u32..7u32 {
if arr[i] > arr[i + 1u32] {
return false;
}
}
return true;
}

transition bubble_sort(
arr0: u32,
arr1: u32,
Expand Down Expand Up @@ -282,6 +291,8 @@ program bubblesort.aleo {
arr1 = temp;
}

assert(is_sorted([arr0, arr1, arr2, arr3, arr4, arr5, arr6, arr7]));

return (arr0, arr1, arr2, arr3, arr4, arr5, arr6, arr7);
}
}