BUBBLE SORT


 

 


 

The Algorithm Pseudocode:

bubblesort (A, N)

{ repeat the following steps until the list is sorted
  put 1 into i
  repeat while i < N
     if A[i] > A[i+1]
          then swap A[i], A[i+1]
     end if
     add 1 to i
  end repeat
end repeat
}end bubblesort



The bubble sort algorithm:
  1. Compare adjacent elements. If the first is greater than the second, swap them.

  2. Do this for each pair of adjacent elements, starting with the first two and ending with the last two. At this point the last element should be the greatest.

  3. Repeat the steps for all elements except the last one.

  4. Continue for one less element each time, until there are no more pairs to compare.