Private Sub BubbleSortNumbers(varray As Variant)
Dim cnt1 As Long
Dim cnt2 As Long
Dim tmp As Long
Dim counter As Long
Label12.Caption = "Working..."
For cnt1 = UBound(varray) To LBound(varray) Step -1
For cnt2 = LBound(varray) + 1 To cnt1
If varray(cnt2 - 1) > varray(cnt2) Then
tmp = varray(cnt2 - 1)
varray(cnt2 - 1) = varray(cnt2)
varray(cnt2) = tmp
'-----------------------------
'Required for the speed Test;
'comment out for real use
counter = counter + 1
DoEvents
If SkipFlag Then Exit For
'----------------------------
End If
Next cnt2
Next cnt1
Label12.Caption = "Elements swapped : " & counter
End Sub
Private Sub QuickSortNumbers(varray As Variant, inLow As Long, inHigh As Long)
'varray() The varray to sort
'inLow First element of varray to start sort
'inHigh Last element of varray to start sort
'----------------------------------------------------
'update the call count label; comment out for real use
QSCallCnt = QSCallCnt + 1
'----------------------------------------------------
Dim pivot As Long
Dim tmpSwap As Long
Dim tmpLow As Long
Dim tmpHigh As Long
tmpLow = inLow
tmpHigh = inHigh
pivot = varray((inLow + inHigh) / 2)
While (tmpLow <= tmpHigh)
While (varray(tmpLow) < pivot And tmpLow < inHigh)
tmpLow = tmpLow + 1
Wend
While (pivot < varray(tmpHigh) And tmpHigh > inLow)
tmpHigh = tmpHigh - 1
Wend
If (tmpLow <= tmpHigh) Then
tmpSwap = varray(tmpLow)
varray(tmpLow) = varray(tmpHigh)
varray(tmpHigh) = tmpSwap
tmpLow = tmpLow + 1
tmpHigh = tmpHigh - 1
'----------------------------------------------------
'update the swap count label ; comment out for real use
QSSwaps = QSSwaps + 1
'----------------------------------------------------
End If
Wend
If (inLow < tmpHigh) Then QuickSortNumbers varray, inLow, tmpHigh
If (tmpLow < inHigh) Then QuickSortNumbers varray, tmpLow, inHigh
Label15.Caption = "Sub was called : " & QSCallCnt & " times"
Label16.Caption = "Elements Swapped : " & QSSwaps
End Sub
Private Sub SelectionSortNumbers(varray As Variant)
Dim cnt1 As Long
Dim cnt2 As Long
Dim nMin As Long
Dim tmp As Long
Dim counter As Long
Label13.Caption = "Working..."
For cnt1 = LBound(varray) To UBound(varray) - 1
nMin = cnt1
For cnt2 = (cnt1 + 1) To UBound(varray)
If varray(cnt2) < varray(nMin) Then
nMin = cnt2
'----------------------------------------------------
'comment out for real use
'update the iterations label
counter = counter + 1
'----------------------------------------------------
End If
'----------------------------------------------------
'Required to enable abort of speed Test;
'comment out for real use
DoEvents
If SkipFlag Then Exit For
'----------------------------------------------------
Next cnt2
tmp = varray(nMin)
varray(nMin) = varray(cnt1)
varray(cnt1) = tmp
Next cnt1
Label13.Caption = "Elements swapped : " & counter
End Sub
Private Sub ShellSortNumbers(varray As Variant)
Dim cnt As Long
Dim tmp As Long
Dim nHold As Long
Dim nHValue As Long
Dim counter As Long
Label14.Caption = "Working..."
nHValue = LBound(varray)
Do
nHValue = 3 * nHValue + 1
Loop Until nHValue > UBound(varray)
Do
nHValue = nHValue / 3
For cnt = nHValue + LBound(varray) To UBound(varray)
tmp = varray(cnt)
nHold = cnt
Do While varray(nHold - nHValue) > tmp
varray(nHold) = varray(nHold - nHValue)
nHold = nHold - nHValue
'----------------------------------------------------
'Required for the speed Test; comment out for real use
'update the iterations label
counter = counter + 1
DoEvents
'----------------------------------------------------
If nHold < nHValue Then Exit Do
Loop
varray(nHold) = tmp
Next cnt
Loop Until nHValue = LBound(varray)
Label14.Caption = "Elements swapped : " & counter
End Sub
Dim cnt1 As Long
Dim cnt2 As Long
Dim tmp As Long
Dim counter As Long
Label12.Caption = "Working..."
For cnt1 = UBound(varray) To LBound(varray) Step -1
For cnt2 = LBound(varray) + 1 To cnt1
If varray(cnt2 - 1) > varray(cnt2) Then
tmp = varray(cnt2 - 1)
varray(cnt2 - 1) = varray(cnt2)
varray(cnt2) = tmp
'-----------------------------
'Required for the speed Test;
'comment out for real use
counter = counter + 1
DoEvents
If SkipFlag Then Exit For
'----------------------------
End If
Next cnt2
Next cnt1
Label12.Caption = "Elements swapped : " & counter
End Sub
Private Sub QuickSortNumbers(varray As Variant, inLow As Long, inHigh As Long)
'varray() The varray to sort
'inLow First element of varray to start sort
'inHigh Last element of varray to start sort
'----------------------------------------------------
'update the call count label; comment out for real use
QSCallCnt = QSCallCnt + 1
'----------------------------------------------------
Dim pivot As Long
Dim tmpSwap As Long
Dim tmpLow As Long
Dim tmpHigh As Long
tmpLow = inLow
tmpHigh = inHigh
pivot = varray((inLow + inHigh) / 2)
While (tmpLow <= tmpHigh)
While (varray(tmpLow) < pivot And tmpLow < inHigh)
tmpLow = tmpLow + 1
Wend
While (pivot < varray(tmpHigh) And tmpHigh > inLow)
tmpHigh = tmpHigh - 1
Wend
If (tmpLow <= tmpHigh) Then
tmpSwap = varray(tmpLow)
varray(tmpLow) = varray(tmpHigh)
varray(tmpHigh) = tmpSwap
tmpLow = tmpLow + 1
tmpHigh = tmpHigh - 1
'----------------------------------------------------
'update the swap count label ; comment out for real use
QSSwaps = QSSwaps + 1
'----------------------------------------------------
End If
Wend
If (inLow < tmpHigh) Then QuickSortNumbers varray, inLow, tmpHigh
If (tmpLow < inHigh) Then QuickSortNumbers varray, tmpLow, inHigh
Label15.Caption = "Sub was called : " & QSCallCnt & " times"
Label16.Caption = "Elements Swapped : " & QSSwaps
End Sub
Private Sub SelectionSortNumbers(varray As Variant)
Dim cnt1 As Long
Dim cnt2 As Long
Dim nMin As Long
Dim tmp As Long
Dim counter As Long
Label13.Caption = "Working..."
For cnt1 = LBound(varray) To UBound(varray) - 1
nMin = cnt1
For cnt2 = (cnt1 + 1) To UBound(varray)
If varray(cnt2) < varray(nMin) Then
nMin = cnt2
'----------------------------------------------------
'comment out for real use
'update the iterations label
counter = counter + 1
'----------------------------------------------------
End If
'----------------------------------------------------
'Required to enable abort of speed Test;
'comment out for real use
DoEvents
If SkipFlag Then Exit For
'----------------------------------------------------
Next cnt2
tmp = varray(nMin)
varray(nMin) = varray(cnt1)
varray(cnt1) = tmp
Next cnt1
Label13.Caption = "Elements swapped : " & counter
End Sub
Private Sub ShellSortNumbers(varray As Variant)
Dim cnt As Long
Dim tmp As Long
Dim nHold As Long
Dim nHValue As Long
Dim counter As Long
Label14.Caption = "Working..."
nHValue = LBound(varray)
Do
nHValue = 3 * nHValue + 1
Loop Until nHValue > UBound(varray)
Do
nHValue = nHValue / 3
For cnt = nHValue + LBound(varray) To UBound(varray)
tmp = varray(cnt)
nHold = cnt
Do While varray(nHold - nHValue) > tmp
varray(nHold) = varray(nHold - nHValue)
nHold = nHold - nHValue
'----------------------------------------------------
'Required for the speed Test; comment out for real use
'update the iterations label
counter = counter + 1
DoEvents
'----------------------------------------------------
If nHold < nHValue Then Exit Do
Loop
varray(nHold) = tmp
Next cnt
Loop Until nHValue = LBound(varray)
Label14.Caption = "Elements swapped : " & counter
End Sub