Bubble Sort

Bubble sort is a simple sorting algorithm that works by repeatedly iterating through the list of items to be sorted, comparing adjacent items and swapping them if they are in the wrong order. The algorithm repeats this process until no more swaps are needed, which means the list is sorted.

Here’s the basic outline of the algorithm:

1) Set a flag to true.
2) While the flag is true, repeat the following:
3) Set the flag to false.
4) Iterate through the list of items. For each pair of adjacent items:
5) If the two items are in the wrong order, swap them and set the flag to true.
6) Return the sorted list.

function bubble_sort(array):
    flag = true
    while flag:
        flag = false
        for i in 0 to length of array - 2:
            if array[i] > array[i+1]:
                swap array[i] and array[i+1]
                flag = true
    return array