Quick Sort 2 : Array Sort « Data Type « VBA / Excel / Access / Word

Home
VBA / Excel / Access / Word
1.Access
2.Application
3.Data Type
4.Data Type Functions
5.Date Functions
6.Excel
7.File Path
8.Forms
9.Language Basics
10.Math Functions
11.Outlook
12.PowerPoint
13.String Functions
14.Windows API
15.Word
16.XML
VBA / Excel / Access / Word » Data Type » Array Sort 
Quick Sort 2
 
Sub Main()
   Dim myArray(4As Double
   myArray(09
   myArray(111
   myArray(27
   myArray(34
   
   Call QSort(myArray, 04)

   Debug.Print myArray(0)
   Debug.Print myArray(1)
   Debug.Print myArray(2)
   Debug.Print myArray(3)

End Sub

Sub QSort(sortArray() As Double, ByVal leftIndex As Integer, _
                                     ByVal rightIndex As Integer)
    Dim compValue As Double
    Dim As Integer
    Dim As Integer
    Dim tempNum As Double

    I = leftIndex
    J = rightIndex
    compValue = sortArray(Int((I + J2))

    Do
        Do While (sortArray(I< compValue And I < rightIndex)
            I = I + 1
        Loop
        Do While (compValue < sortArray(JAnd J > leftIndex)
            J = J - 1
        Loop
        If I <= J Then
            tempNum = sortArray(I)
            sortArray(I= sortArray(J)
            sortArray(J= tempNum
            I = I + 1
            J = J - 1
        End If
    Loop While I <= J

    If leftIndex < J Then QSort sortArray(), leftIndex, J
    If I < rightIndex Then QSort sortArray(), I, rightIndex
End Sub

 
Related examples in the same category
1.VBA Bubble Sort
2.using dynamic arrays in bubble sort
3.Performing a Binary Search through an Array
4.Quick sort
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.