Дан массив A, заполненный 10 произвольными латинскими буквами, упорядочить их любым методом(пузырька или выбором или быстрая сортировка)
Дан массив A, заполненный 10 произвольными латинскими буквами, упорядочить их любым методом(пузырька или выбором или быстрая сортировка)
Ответ(ы) на вопрос:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim Array() As Byte = {102, 103, 105, 105, 104, 108, 101, 109, 111, 113}
GnomeSort(Array, True)
End Sub
' // Алгоритм гномьей сортировки
Sub GnomeSort(ByRef Array() As Byte, ByVal ToUpper As Boolean)
Dim tui As Integer, index As Integer, last As Integer
If (ToUpper = True) Then tui = 1 Else tui = -1
index = 1
last = 2
Do
If ((Array(index) * tui) < (Array(index - 1) * tui)) Then
SWAP(Array(index), Array(index - 1))
index -= 1
If (index = 0) Then
index = last
last += 1
End If
Else
index = last
last += 1
End If
Loop While (index < (UBound(Array) + 1))
' // c2fbefeeebede8eb3a20caf3eff0e8ffedeee220c42ec52e2028632920442d6d6f6e3535
End Sub
' // Функция обмена двух переменных
Private Function SWAP(ByRef ic_a As Integer, ByRef ic_b As Integer) As Boolean
Dim Dump As Integer = ic_a
ic_a = ic_b
ic_b = Dump
Return True
End Function
Не нашли ответ?
Похожие вопросы