Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
PUBLIC SUB
Main()
Ejemplos de ordenamiento por el mtodo
burbuja:
Public
num As Integer
DIM Columna AS Integer
Public numeritos As String
DIM N, i, j, Aux AS Integer
Public Sub Form_Open()
DIM Limite AS Integer
DIM vector AS Integer[]
vector = NEW Integer[]
PRINT Ingrese el limite mximo a leer el
vector:
INPUT Limite
FOR Columna = 0 TO Limite
PRINT Ingresa un Numero
INPUT N
vector.Add(N)
NEXT
Este es el Procedimiento Burbuja
para ordenar los datos que contiene
el vector
FOR i = 0 TO Limite 1
FOR j = 0 TO Limite 1
IF Vector[j] > vector[j + 1] THEN
En esta parte se realiza el intercambio
Aux = vector[j]
vector[j] = vector[j + 1]
vector[j + 1] = Aux
END IF
NEXT
NEXT
PRINT
Por ultimo procedemos a imprimir el
vector
FOR j = 0 TO Limite
PRINT vector[j]
NEXT
END
2. Ordenamiento Por Insercin
Me.Center
End
Public Sub Button1_Click()
Dim arrayNum As Integer[] = ["55", "86", "48",
"16", "82"]
Dim x, y, a, s, Rota1, Rota2 As Integer
TextArea1.Clear
Repeat
If a = 4 Then a = 0
If y = 4 Then y = 0
If arrayNum[y] < arrayNum[a + 1] Then
Inc y
Inc a
Inc s
Continue
Endif
Rota1 = 0
Rota2 = 0
Rota1 = arrayNum[y]
Rota2 = arrayNum[a + 1]
arrayNum[y] = Rota2
arrayNum[a + 1] = Rota1
Dec s
For Each num In arrayNum
numeritos &= num & " "
Wait 0.2
Next
TextArea1.Text &= numeritos & gb.NewLine
numeritos = ""
Until s > 4
For Each num In arrayNum
numeritos &= num & " "
Wait 0.2
Next
TextArea1.Text &= gb.NewLine & "Resultado
final es: " & numeritos & gb.NewLine
End
43
65 84 45
//ordenacin
2 hasta
N comparaciones
hacer
ElDesde
mtodoI se
basa en
y desplazamientos sucesivos. El
algoritmo de clasificaciones de un vector X para N elementos se realiza con un
AUXI X [I]
recorrido de todo el vector y la insercin del elemento correspondiente en el
lugar
K I -adecuado.
1
ElSW
recorrido
false se realizaza desde el segundo elemento al n-simo.
Desde
i 2 hasta
N hacer
mientras
no (SW)
y (k >= 1) hacer
Insertar
lugar adecuado
si AUXIX[i]
< X en
[ ] el
entonces
Entre
X [ Kx+[1].
1 ] .XX[ [i
K -] 1]
fin_desde
K [K 1]
Esta
accin repetitiva - insertar- se realiza ms fcilmente con la inclusin de
si_no
un valor centinela o bandera. (SW).
SW verdad
fin_si
fin_mientras
X [ K + 1 ] AUXI
fin_desde
fin
Recorrido
Salto
Lista
Ordenada
Intercambio
2,1,4,0,3,5,6
(6,2), (5,4),
(6,0)
0,1,4,2,3,5,6
(2,0)
0,1,4,2,3,5,6
Ninguno
0,1,2,3,4,5,6
(4,2), (4,3)
0,1,2,3,4,5,6
Ninguno