VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Simple 1d array bubble sort module

by Colin Woor (2 Submissions)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

Simply sorts a 1 dimensional array using a bubble sort algorythm.

Inputs
Array to be sorted
Code Returns
A sorted array

Rate Simple 1d array bubble sort module

'
'Use:
'
'Sort Array
'
'to sort (A-Z / 1-10, Accending)
'Pretty easy to update it to sort 2 or 3 dimensional arrays
'Or to sort decending
'
'Comments or any info email: [email protected]
'
Public Sub sort(tmparray)
Dim SortedArray As Boolean
Dim start, Finish As Integer
SortedArray = True
start = LBound(tmparray)
Finish = UBound(tmparray)
Do
  SortedArray = True
  For loopcount = start To Finish - 1
    
    If tmparray(loopcount) > tmparray(loopcount + 1) Then
      SortedArray = False
      Call swap(tmparray, loopcount, loopcount + 1)
    End If
    
  Next loopcount
Loop Until SortedArray = True

End Sub
Sub swap(swparray, fpos, spos)
Dim temp As Variant
temp = swparray(fpos)
swparray(fpos) = swparray(spos)
swparray(spos) = temp
End Sub

Download this snippet    Add to My Saved Code

Simple 1d array bubble sort module Comments

No comments have been posted about Simple 1d array bubble sort module. Why not be the first to post a comment about Simple 1d array bubble sort module.

Post your comment

Subject:
Message:
0/1000 characters