Bubble Sort

A bubble sort is a very simple and easy to understand way of sorting. Look at the example below. The procedure is passed an array of 'Integer' values. The procedure starts at the first index in the array then checks to see if the next integer in the array is smaller. If it is, the integer at the current position is swapped with the one that comes after it. Then the CurPos varible is set back to the first index in the array. The process is then repeated until the all the numbers in the array have been sorted.

VB6 Example:
========

Sub SortNumbers(Nums() as Integer)
  Dim CurPos As Integer
  Dim Tmp As Integer

  CurPos = LBound(Nums)
  Do While CurPos < UBound(Nums)
    If Nums(CurPos) > Nums(CurPos + 1) Then
      Tmp = Nums(CurPos + 1)
      Nums(CurPos + 1) = Nums(CurPos)
      Nums(CurPos) = Tmp

      CurPos = LBound(Nums) - 1
    End If

    CurPos = CurPos + 1
  Loop
End Sub

Created by: X

Just another personal website in this crazy online world

Name of author Dean Lunz (aka Created by: X)
Computer programming nerd, and tech geek.
About Me -- Resume