Bubble Sort
Bubble Sort
BY AMBRISH GANGAL
WHAT IS IT ??
Bubble sort, also known as sinking sort, is a simple sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted.
HOW IT WORKS ??
DATA is an array with N elements 1. Repeat steps 2 and 3 for K = 1 to N-1 2. Set PTR=1[initializes pass pointer PTR] 3. Repeat while PTR<= N-K[Executes Pass] a) if DATA[PTR]>DATA[PTR+1]then interchange DATA [PTR] and DATA [PTR+1] [End of if structure] b) Set PTR=PTR+1. [End of inner loop] 4. Exit
EXAMPLE :
END OF BUBBLE