Dim info(10) As String
Dim link(10) As Integer
Dim i As Integer
Dim caracter As String
Dim comienzo = 0, puntero As Integer
Dim disp As Integer = 1
Dim nuevo As Integer
Dim caracter_nuevo As String
Dim dato_ins, dato_ref As String
Dim puntero2, puntero3, puntero_anterior, encontrado As Integer
Dim aux As Integer
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
fecha.Text = Date.Now
' info(1) = "V"
' info(2) = "D"
' info(3) = "C"
' info(5) = "I"
' info(6) = "O"
' info(7) = "9"
'info(8) = "1"
link(1) = 2
link(2) = 3
link(3) = 4
link(4) = 5
link(5) = 6
link(6) = 7
link(7) = 8
link(8) = 9
link(9) = 10
link(10) = 0
grid_info.Hide()
grid_link.Hide()
grid_recorrido.Hide()
End Sub
Private Sub limpiar_Click(sender As Object, e As EventArgs) Handles
limpiar.Click
dato.Text = ""
End Sub
Private Sub salir_Click(sender As Object, e As EventArgs) Handles salir.Click
End
End Sub
Private Sub ocultar_info_Click(sender As Object, e As EventArgs) Handles
ocultar_info.Click
grid_info.Hide()
End Sub
Private Sub mostrar_info_Click(sender As Object, e As EventArgs) Handles
mostrar_info.Click
grid_info.AllowUserToAddRows = False
grid_info.RowHeadersVisible = False
grid_info.Show()
For i = 1 To 10
grid_info.Rows.Add(i, info(i))
Next
End Sub
Private Sub ocultar_link_Click(sender As Object, e As EventArgs) Handles
ocultar_link.Click
grid_link.Hide()
End Sub
Private Sub mostrar_link_Click(sender As Object, e As EventArgs) Handles
mostrar_link.Click
grid_link.AllowUserToAddRows = False
grid_link.RowHeadersVisible = False
grid_link.Show()
x = comienzo
For i = 1 To 10
grid_link.Rows.Add(i, link(i))
Next
x = info(x)
End Sub
Private Sub RECORRIDO_Click(sender As Object, e As EventArgs) Handles
RECORRIDO.Click
grid_recorrido.AllowUserToAddRows = False
grid_recorrido.RowHeadersVisible = False
grid_recorrido.Show()
grid_recorrido.Rows.Clear()
puntero = comienzo
Do
grid_recorrido.Rows.Add(rich.Text & info(puntero))
puntero = link(puntero)
Loop Until puntero = 0
If puntero = 0 Then
MsgBox("EL PUNTERO YA ES 0, RECORRIDO TERMINADO")
End If
End Sub
Private Sub insertar_Click(sender As Object, e As EventArgs) Handles
insertar.Click
MsgBox("Vuelva a cargar el recorrido para visualizarlo")
If r_enfrende.Checked Then
caracter = dato_insertar.Text
If disp = 0 Then
MsgBox("OVERFLOW, LISTA LLENA!")
Exit Sub
Else
nuevo = disp
disp = link(disp)
info(nuevo) = caracter
link(nuevo) = comienzo
comienzo = nuevo
End If
ElseIf r_atras.Checked Then
caracter_nuevo = dato_insertar.Text
If disp = 0 Then
MsgBox("OVERFLOW, LISTA LLENA!")
Exit Sub
Else
nuevo = disp
disp = link(disp)
info(nuevo) = caracter_nuevo
link(nuevo) = 0
puntero = 0
Do
puntero += 1
Loop Until link(puntero) = 0
link(puntero) = nuevo
End If
End If
End Sub
Private Sub nuevo_dato_insertar_Click(sender As Object, e As EventArgs) Handles
nuevo_dato_insertar.Click
dato_insertar.Text = ""
r_atras.Checked = True
r_enfrende.Checked = False
End Sub
Dim ant, y, x, ex As Integer
Private Sub eliminar_nodos_Click(sender As Object, e As EventArgs) Handles
eliminar_nodos.Click
If primero.Checked Then
If disp = 0 Then
MsgBox("OVERFLOW, LISTA LLENA!")
Exit Sub
Else
aux = link(comienzo)
link(comienzo) = disp
disp = comienzo
comienzo = aux
End If
ElseIf ultimo.Checked Then
If disp = 0 Then
MsgBox("OVERFLOW, LISTA LLENA!")
ex = 1
Exit Sub
Else
y = comienzo
While (y <> 0)
If link(y) = 0 Then 'ya casi hay problemas con las variables
puntero = 0
y = 0
x = 1
Else
ant = y
End If
y = link(y)
End While
link(puntero) = disp
disp = puntero
If ant > 0 Then
link(ant) = 0
Else
comienzo = 0
End If
ex = 0
End If
End If
End Sub
Private Sub Insertar_nuevo_dato_posicion_Click(sender As Object, e As
EventArgs) Handles Insertar_nuevo_dato_posicion.Click
dato_insertar_posicion.Text = ""
dato_referencia.Text = ""
radio_atras.Checked = False
radio_enfrente.Checked = True
End Sub
Private Sub insertar_posicion_Click(sender As Object, e As EventArgs) Handles
insertar_posicion.Click
dato_ins = dato_insertar_posicion.Text
dato_ref = dato_referencia.Text
encontrado = 0
If radio_enfrente.Checked Then
puntero2 = comienzo
If dato_ref = "" Or dato_ins = "" Then
MsgBox("Ingrese un caracter valido")
Exit Sub
ElseIf disp = 0 Then
MsgBox("OVERFLOW, LISTA LLENA!")
Exit Sub
End If
Do
If dato_ref = info(puntero2) Then
encontrado = 1
puntero = puntero2
MsgBox("Encontrado en la posicion #: " & puntero2)
MsgBox("Interseccion exitosa")
Exit Do
End If
puntero2 = link(puntero2)
Loop Until puntero2 = 0
If encontrado = 1 Then
nuevo = disp
disp = link(disp)
info(nuevo) = dato_ins
link(nuevo) = link(puntero)
link(puntero) = nuevo
Else
MsgBox("ERROR")
End If
ElseIf radio_atras.Checked Then
puntero3 = comienzo
If dato_ref = "" Or dato_ins = "" Then
MsgBox("Ingrese un caracter valido")
Exit Sub
ElseIf disp = 0 Then
MsgBox("OVERFLOW, LISTA LLENA!")
Exit Sub
End If
Do
If dato_ref = info(puntero3) Then
encontrado = 1
puntero = puntero3
MsgBox("Encontrado en la posicion #: " & puntero3)
MsgBox("Interseccion exitosa")
Exit Do
Else
puntero_anterior = puntero3
End If
puntero3 = link(puntero3)
Loop Until puntero3 = 0
If encontrado = 1 Then
nuevo = disp
disp = link(disp)
info(nuevo) = dato_ins
link(nuevo) = puntero
link(puntero_anterior) = nuevo
End If
End If
End Sub
Private Sub Buscar_Click(sender As Object, e As EventArgs) Handles Buscar.Click
caracter = dato.Text
puntero = comienzo
Do
If caracter = info(puntero) Then
MessageBox.Show("SI SE ENCONTRO, ESTA EN LA POSICION: " & puntero,
"ENCONTRADO", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Do
Else
puntero = link(puntero)
End If
Loop Until puntero = 0
End Sub