vbnewbie
07-19-2003, 08:16 AM
well, they say bubble sort is the easiest sort to learn but i just don't seem to get it, if someone knows where there is a well documented bubble sort example or some one could show me a ssmall documented example, that would be great.
i am new to vb and am trying to find basically, a line by line documented example of a bubble sort so i can get my head around it and move on to more complex matters.
any help anyone can give will be appreciated, thanks
Iceplug
07-19-2003, 08:33 AM
http://www.visualbasicforum.com/showthread.php?t=78889&highlight=sorting
Have you seen this thread?
Robse
07-19-2003, 09:09 AM
Nice applet:
http://www.sitemonitor.com/sort/
vbnewbie
07-19-2003, 10:41 AM
i understand this code pretty good
but can someone show me where the name of my array (which is xxx) goes? do i replace lngArray with mine or put it in the ()?
the first line has me the most confused
and what does ByRef mean, do?
thanks
us newbies are a pain, right? :)
----------------------------------------------------------------
Public Sub BubbleSort(ByRef lngArray() As Long)
Dim iOuter As Long
Dim iInner As Long
Dim iLBound As Long
Dim iUBound As Long
Dim iTemp As Long
iLBound = LBound(lngArray)
iUBound = UBound(lngArray)
'Which bubbling pass
For iOuter = iLBound To iUBound - 1
'Which comparison
For iInner = iLBound To iUBound - iOuter - 1
'Compare this item to the next item
If lngArray(iInner) > lngArray(iInner + 1) Then
'Swap
iTemp = lngArray(iInner)
lngArray(iInner) = lngArray(iInner + 1)
lngArray(iInner + 1) = iTemp
End If
Next iInner
Next iOuter
Bobo the Thief
07-19-2003, 03:00 PM
Of course you replace IngArray with your array. You newbies are very much a pain, but not here at VBF.
You should read Programming Fundamentals somewhere (there's nothing more fundamental than ByRef - specified when passing a routine parameter By Reference, that is in order to work precisely with the array that is passed).