Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting An Array

Status
Not open for further replies.

frOblivion

Programmer
Jan 2, 2001
14
US
Are there any good functions for sorting an array of integers?
 
Sub Sort_A(lngOld() As Long)
'*****
'* Sort Old ascending
'*****
Dim I As Long, _
J As Long, _
lngN As Long, _
lngGAP As Long, _
JGap As Long, _
wLng As Long
Dim lngNo As Long
lngNo = UBound(lngOld)
Dim w1st As Long, _
w2nd As Long, _
w1stGap As Long, _
w2ndGap As Long
' S H E L L S O R T


lngN = lngNo


lngGAP = 1
Do While (lngGAP < lngN)
lngGAP = lngGAP * 3 + 1
Loop
lngGAP = (lngGAP - 1) \ 3
Do While lngGAP > 0
For I = lngGAP + 1 To lngN
J = I - lngGAP
JGap = J + lngGAP
Do While J > 0
w1st = lngOld(J) ' ABSolute value
If w1st < 0 Then w1st = -w1st

w1stGap = lngOld(JGap)
If w1stGap < 0 Then w1stGap = -w1stGap

If w1st < w1stGap Then Exit Do

wLng = lngLCSOld(J)
lngOld(J) = lngOld(JGap)
lngOld(JGap) = wLng

JGap = J
J = J - lngGAP
Loop
Next
If lngGAP <= 1 Then Exit Do
lngGAP = (lngGAP - 1) \ 3
Loop
'For I = 2 To UBound(lngOld)
' Debug.Print &quot;Old=&quot; & lngOld(I)
'Next
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top