Algorithm - Bubble Sort                                                      Home :





Bubble Sort


Bubble Sort is an algorithm to rearrange the elements in an array(or List) in a certain order (e.g, increasing order / decreasing order).


    i) An array (or List) is given. Let's call this array as A[]

    ii) Do the followings

          Label : StartOver

          Set a position of index i = 0

          set the status variable SwapFlag = False

            Label : ShiftAndSwap

          if A[i] > A[i+1] then   // Check if the current element value > the next element value

             Swap the value between A[i] and A[i+1]

             SwapFlag = True


             i = i + 1  // move to next position

                if i is not the end of array, go to ShiftAndSwap

         if SwapFlag = False, go to StartOver