1
I have a class assignment whose need is to use an sorting algorithm to sort a list of random numbers.
My problem is that I am throwing the items from the random number list into an array, implementing the sort method and placing the ordered numbers into a second list.
But when I am doing this it always returns the number 0, or the error int32[] array. How should I proceed?
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim min As Integer
Dim max As Integer
Dim i As Integer
Dim j As Integer
Dim best_value As Long
Dim best_j As Integer
For i = min To max - 1
best_value = ve(i)
best_j = i
For j = i + 1 To max
If ve(j) < best_value Then
best_value = ve(j)
best_j = j
End If
Next j
vl(best_j) = vl(i)
vl(i) = best_value
Next i
Dim h As Integer
For h = 0 To 1
Lst.Items.Add(vl(h))
Next h
End Sub
In this code VE
is the random number array, VL
is the array of numbers already sorted and lst
is the listbox to which the ordered numbers go.
A valuable tip: use more descriptive names for their variables. Names like
X
,Y
,VE
, etc. are not good at all.– Jéf Bueno
Thank you, I will follow your tips =D
– Talisonzb
Talison, your code is not initializing the max variable, so the loop (For i = min To max - 1) will never run. Check this and if the problem persists put the modified code to help you.
– Bruno Bermann