I am so lost with this Bubble Sort array. I am trying to alphabetize these baseball players. Having a lot of trouble getting everything right.
Public Class frmBubbleSort
' Declare array with Class (form) scope
Dim players As String() = {"Crawford", "Upton", "Longoria", "Bartlett", "Pena", "Navarro", "Garza", "Shields", "Price", "Neiman"}
Dim A As Integer = 1
Private Sub frmBubbleSort_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Load array into ComboBox
Array.Sort(players)
cboBubble.MaxDropDownItems = players
cboBubble.DataSource = A
End Sub
Private Sub Swap(ByRef first As String, ByRef second As String)
' Define Swap Method
If first > second Then
Swap(first, second)
End If
Dim temp As String ' local variable for swap method
temp = first
first = second
second = temp
End Sub
Private Sub btnSort_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSort.Click
' number of passes is one less than the number of items
For passnum As String = 1 To players - 1 ' pass loop
' comparison loop - each pass needs one less comparison
For i As Integer = 1 To players - passnum 'comparison loop
If A(i - 1) > A(i) Then ' comparison
Swap(A(i - 1), A(i)) 'call swap and overwrite original values
End If
Next ' End of loop for comparisons
Next ' end of loop for pass
' Display sorted array in ListBox
For i As Integer = 0 To players - 1
lstSort.Items.Add(A(i))
Next
End Sub ' End of Click Event
Private Sub BubbleSort_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load