Array Elements are sorted slowly to their proper location, by comparing each element with adjacent element continuously until the sorting is complete.
First element is taken and compared with the remaining set of elements one after the other and then it is swapped to its correct position. Then the second element is compared and moved, the comparison and swapping of elements continues until the array comes to a sorted manner i.e., there is no need of swaps anymore.
Bubble sort tracks the swap using a flag. Below is an example which explains the scenario:
Array: 84 69 76 86 94 91
After Pass #1: 84 76 86 94 91 69
After Pass #2: 84 86 94 91 76 69
After Pass #3: 86 94 91 84 76 69
After Pass #4: 94 91 86 84 76 69
After Pass #5 (Completed): 94 91 86 84 76 69