document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. \' Gambas class file
  2.  
  3. Public v0 As Nodo
  4. Public v1 As Nodo
  5. Public v2 As Nodo
  6. Public v3 As Nodo
  7. Public v4 As Nodo
  8. Public v5 As Nodo
  9. Public Nodotemporal As Nodo
  10.  
  11. Public Sub _new()
  12.  
  13. End
  14.  
  15. Public Sub Form_Open()
  16.   \'Ejemplo listas Enlazadas
  17.  
  18.   definirNodosYenlazarlos()
  19.  
  20.   TextLabel1.text = v0.dato
  21.   TextLabelFrutasSiguen.text = v0.VerLista()
  22.   Nodotemporal = v0
  23.  
  24. End
  25.  
  26. Public Sub definirNodosYenlazarlos()
  27.  
  28.   \'defino los elementos
  29.   v0 = New Nodo("Locomotora")
  30.   v1 = New Nodo("Manzanas")
  31.   v2 = New Nodo("Peras")
  32.   v3 = New Nodo("Bananas")
  33.   v4 = New Nodo("Fresas")
  34.   v5 = New Nodo("Naranjas")
  35.   \'defino los enlaces
  36.   v0.EnlaceHaciaAdelante(v1)
  37.   v1.EnlaceHaciaAdelante(v2)
  38.   v2.EnlaceHaciaAdelante(v3)
  39.   v3.EnlaceHaciaAdelante(v4)
  40.   v4.EnlaceHaciaAdelante(v5)
  41.  
  42. End
  43.  
  44. Public Sub ButtonAdelante_Click()
  45.  
  46.   If IsNull(Nodotemporal.siguiente) Then
  47.     TextLabelFrutasSiguen.text = "Ultimo Elemento"
  48.     Return
  49.   Endif
  50.   Nodotemporal = Nodotemporal.siguiente
  51.  
  52.   TextLabel1.text = Nodotemporal.dato
  53.   TextLabelFrutasSiguen.text = Nodotemporal.VerLista()
  54.  
  55. End
  56.  
  57. Public Sub ButtonReiniciarLista_Click()
  58.  
  59.   Nodotemporal = v0
  60.   TextLabel1.text = Nodotemporal.dato
  61.   TextLabelFrutasSiguen.text = Nodotemporal.VerLista()
  62.  
  63. End
  64.  
  65. Public Sub ButtonAnade_Click()
  66.   \'creo un nuevo nodo
  67.  
  68.   Dim nodoNuevo As New Nodo(TextBoxFrutaNueva.Text)
  69.  
  70.   \'lo meto entre el nodo actual (el temporal) y el que le sigue
  71.   nodoNuevo.EnlaceHaciaAdelante(Nodotemporal.siguiente)
  72.   Nodotemporal.EnlaceHaciaAdelante(nodoNuevo)
  73.   \'muestro la nueva lista de siguientes
  74.   TextLabelFrutasSiguen.text = Nodotemporal.VerLista()
  75.  
  76. End
  77.  
  78. Public Sub ButtonBorra_Click()
  79.  
  80.   Dim nodoSiguienteSiguiente As Nodo
  81.   \'compruebo que el vagon siguiente no es null (no se puede borrar)
  82.   If IsNull(Nodotemporal.siguiente) Then
  83.     Print "No puedo borrar"
  84.   Else
  85.    
  86.     \'lo que hago es obtener el vagon que le siguiente al siguiente
  87.     Nodotemporal.EnlaceHaciaAdelante(Nodotemporal.siguiente.siguiente)
  88.     \'y se lo asigno al vagon actual...
  89.    
  90.     \'muestro la nueva lista de siguientes
  91.     TextLabelFrutasSiguen.text = Nodotemporal.VerLista()
  92.    
  93.   Endif
  94.  
  95. End
');