Listing Sorting
Listing Sorting
For j = 0 To n - 2
iMin = j
For i = j + 1 To n - 1
If asc Then
If CInt(a(i)) < CInt(a(iMin)) Then
iMin = i
End If
Else
If CInt(a(i)) > CInt(a(iMin)) Then
iMin = i
End If
End If
Next
If iMin <> j Then
Dim tap As Integer = CInt(a(j))
a(j) = a(iMin)
a(iMin) = CStr(tap)
ListBox1.Items.Add(String.Join(",", a))
End If
Next
Return a
End Function
Public Function insertionsort(ByRef data() As String, ByVal asc As Boolean) As String()
For i As Integer = 1 To data.Length - 1
Dim j As Integer = i
While (j > 0)
If asc Then
If CInt(data(j - 1)) > CInt(data(j)) Then
Dim tmp As Integer = CInt(data(j - 1))
data(j - 1) = data(j)
data(j) = CStr(tmp)
j -= 1
ListBox1.Items.Add(String.Join(",", data))
Else
Exit While
End If
Else
If CInt(data(j - 1)) < CInt(data(j)) Then
Dim tmp As Integer = CInt(data(j - 1))
data(j - 1) = data(j)
data(j) = CStr(tmp)
j -= 1
ListBox1.Items.Add(String.Join(",", data))
Else
Exit While
End If
End If
End While
Next
Return data
End Function
Public Function selectionsort(ByRef data() As String, ByVal asc As Boolean) As String()
Dim n As Integer = data.Length
For i As Integer = 0 To n - 2
Dim minIndex As Integer = i
For j As Integer = i + 1 To n - 1
If asc Then