Advanced

Bubble Sort

Sort an array of single-digit numbers and print them in order.

Implement bubble sort to sort the array {5, 2, 8, 1, 4} in ascending order, then print the sorted digits.

Requirements:
• Sort the array in-place using bubble sort

• Print the sorted array as digits: 12458

• The array is defined at label ARRAY with 5 elements

• N is stored at label N

Algorithm:

for i = 0 to n-2:
  for j = 0 to n-2-i:
    if array[j] > array[j+1]:
      swap array[j] and array[j+1]
1
2
3
4
5
6
7
8
9
10
11
12
13
14