[2008] Vb question - need help bubble sorting multi-variable array
Hi, I am basically a novice in using vb express and am stuck trying to apply 'bubble' sorting to multivariable array. Here is my code for array with n rows and 2 columns:
Code:
Public Class Form1
Public theArray(n, 2) As Integer
Public n As Integer
Public arraySize As Integer
Private Sub bubble()
'Attempt to bubble sort – does not work’
Dim k As Integer, j As Integer, temp As Integer
For k = 0 To 1 Step 1
For j = 0 To n - 1 Step 1
If (theArray(j, k) > theArray(j + 1, k)) Then
temp = theArray(j + 1, k)
theArray(j + 1, k) = theArray(j, k)
theArray(j, k) = temp
Else
End If
Next j
Next k
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
bubble()
'Looping to add all array entires into a listbox'
Dim i As Integer
Dim j As Integer
For i = 0 To 1 Step 1
For j = 0 To n Step 1
ListBox2.Items.Add(theArray(j, i))
Next
Next
Dim time As String
'Attempt to time the bubble sort – not sure it is working appropriately'
time = Microsoft.VisualBasic.DateAndTime.Timer
Label2.Text = "Time: " & time & " seconds"
End Sub
End Class
Anybody can help this frustrated newbie?
thanks