codigos en vb de orde

Upload: maximo-plix-rex-casimiro

Post on 12-Oct-2015

9 views

Category:

Documents


0 download

TRANSCRIPT

SHELL SORTPublic Sub shellSort()Dim salto As IntegerDim cambios As IntegerDim aux As IntegerDim i As Integersalto = (arr.length / 2)While salto 0cambios = 1While cambios 0cambios = 0For i = salto To arr.length - 1If arr(i - salto) > arr(i) Thenaux = arr(i)arr(i) = arr(i - salto)arr(i - salto) = auxcambios += 1End IfNextEnd Whilesalto /= 2End WhileEnd Sub

SELECCIN SORT' array of integers to hold valuesPrivate a As Integer() = New Integer(99) {}

' number of elements in arrayPrivate x As Integer

' Selection Sort AlgorithmPublic Sub sortArray()Dim i As Integer, j As IntegerDim min As Integer, temp As Integer

For i = 0 To x - 2min = i

For j = i + 1 To x - 1If a(j) < a(min) Thenmin = jEnd IfNext

temp = a(i)a(i) = a(min)a(min) = tempNextEnd Sub

INSERCION SHORTarray of integers to hold valuesPrivate a As Integer() = New Integer(99) {}

' number of elements in arrayPrivate x As Integer

' Insertion Sort AlgorithmPublic Sub sortArray()Dim i As IntegerDim j As IntegerDim index As Integer

For i = 1 To x - 1index = a(i)j = i

While (j > 0) AndAlso (a(j - 1) > index)a(j) = a(j - 1)j = j - 1End While

a(j) = indexNextEnd Sub

QUICKSORT'Ordenacion rapida (QuickSort)Public Shared Sub QuickSort(a As Integer())QuickSort(0, a.Length - 1, a)End Sub

Private Shared Sub QuickSort(ini As Integer, fin As Integer, a As Integer())Dim left As Integer = iniDim right As Integer = finDim mid As Integer = a((ini + fin) \ 2)

Do'Este es el PartitionWhile a(left) < midleft += 1End WhileWhile a(right) > midright -= 1End WhileIf left