Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default Challenge for the day

Found this on the web. Wondered if anyone could (and wanted to) explain
line by line. Basically a very fast sorting method.

Sub QuickSort(List() As Integer)
' Sorts an array using Quick Sort algorithm
' Adapted from "Visual Basic Developers Guide"
' By D.F. Scott

Dim i As Integer, j As Integer, b As Integer
Dim l As Integer, t As Integer, r As Integer, d As Integer

Dim p(1 To 100) As Integer
Dim w(1 To 100) As Integer

k = 1
p(k) = LBound(List)
w(k) = UBound(List)
l = 1
d = 1
r = UBound(List)
Do
toploop:
If r - l < 9 Then GoTo bubsort
i = l
j = r
While j i
comp = comp + 1
If List(i) List(j) Then
swic = swic + 1
t = List(j)
oldx1 = List(j)
oldy1 = j
List(j) = List(i)
oldx2 = List(i)
oldy2 = i
newx1 = List(j)
newy1 = j
List(i) = t
newx2 = List(i)
newy2 = i
d = -d
End If
If d = -1 Then
j = j - 1
Else
i = i + 1
End If
Wend
j = j + 1
k = k + 1
If i - l < r - j Then
p(k) = j
w(k) = r
r = i
Else
p(k) = l
w(k) = i
l = j
End If
d = -d
GoTo toploop
bubsort:
If r - l 0 Then
For i = l To r
b = i
For j = b + 1 To r
comp = comp + 1
If List(j) <= List(b) Then b = j
Next j
If i < b Then
swic = swic + 1
t = List(b)
oldx1 = List(b)
oldy1 = b
List(b) = List(i)
oldx2 = List(i)
oldy2 = i
newx1 = List(b)
newy1 = b
List(i) = t
newx2 = List(i)
newy2 = i
End If
Next i
End If
l = p(k)
r = w(k)
k = k - 1
Loop Until k = 0
End Sub


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Look Up challenge Guntars Excel Worksheet Functions 3 May 25th 09 04:12 AM
Here's a challenge... thorshammer Excel Worksheet Functions 4 August 12th 08 06:15 PM
Who's up for a challenge!! Altec101[_5_] Excel Programming 7 May 19th 06 04:34 PM
A Challenge mjones Excel Programming 5 August 28th 05 09:54 AM
This May Be A Challenge Jose Rojas Excel Programming 0 September 11th 03 11:52 PM


All times are GMT +1. The time now is 11:23 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"