avp-rag-system / data /bubble_sort.avp
valachmr
Added .avp files from the pre-implemented library
70f40ac unverified
raw
history blame contribute delete
617 Bytes
// bubble sort
a1 = arr[1, 10, 5, 6, 4, 7, 19]
// Sorts an array of values in ascending order
fun Bubble_Sort(@init<table> array):
n = length(array)
for (i = 0, i < n, i += 1):
swapped = False
for (j = 0, j < n - i - 1, j += 1):
@mark<j, outline, yellow> if (array[j] > array[j + 1]):
@mark<j, highlight, green> swap (array[j], array[j+1])
swapped = True
end if
end for
if (swapped == False):
break
end if
end for
return array
end fun
result = Bubble_Sort(a1)