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.siguiente = v1
  37.   v0.previo = Null \'inicio de la lista
  38.  
  39.   v1.siguiente = v2
  40.   v1.previo = v0
  41.  
  42.   v2.siguiente = v3
  43.   v2.previo = v1
  44.  
  45.   v3.siguiente = v4
  46.   v3.previo = v2
  47.  
  48.   v4.siguiente = v5
  49.   v4.previo = v3
  50.  
  51.   v5.previo = v4
  52.   v5.siguiente = Null \'final de la lista
  53.  
  54. End
  55.  
  56. Public Sub ButtonAdelante_Click()
  57.  
  58.   If IsNull(Nodotemporal.siguiente) Then
  59.     TextLabelFrutasSiguen.text = "Ultimo Elemento"
  60.     Return
  61.   Endif
  62.   Nodotemporal = Nodotemporal.siguiente
  63.  
  64.   TextLabel1.text = Nodotemporal.dato
  65.   TextLabelFrutasSiguen.text = Nodotemporal.VerLista()
  66.  
  67. End
  68.  
  69. Public Sub ButtonReiniciarLista_Click()
  70.  
  71.   Nodotemporal = v0
  72.   TextLabel1.text = Nodotemporal.dato
  73.   TextLabelFrutasSiguen.text = Nodotemporal.VerLista()
  74.  
  75. End
  76.  
  77. Public Sub ButtonAnade_Click()
  78.  
  79.   Dim ntmp As Nodo
  80.   \'creo un nuevo nodo
  81.  
  82.   Dim nodoNuevo As New Nodo(TextBoxFrutaNueva.Text)
  83.  
  84.   \'lo meto entre el nodo actual (el temporal) y el que le sigue
  85.  
  86.   nodoNuevo.siguiente = Nodotemporal.siguiente
  87.   ntmp = nodoNuevo.siguiente
  88.  
  89.   \'hacia adelante
  90.   Nodotemporal.siguiente = nodoNuevo
  91.   \'hacia atras
  92.   nodoNuevo.previo = Nodotemporal
  93.   ntmp.previo = nodoNuevo
  94.  
  95.   \'muestro la nueva lista de siguientes
  96.   TextLabelFrutasSiguen.text = Nodotemporal.VerLista()
  97.  
  98. End
  99.  
  100. Public Sub ButtonBorra_Click()
  101.  
  102.   \'compruebo que el vagon siguiente no es null (no se puede borrar)
  103.   If IsNull(Nodotemporal.previo) Then
  104.     Print "No puedo borrar"
  105.   Else
  106.    
  107.     \'lo que hago es obtener el vagon que le siguiente al siguiente
  108.     Nodotemporal.previo.siguiente = Nodotemporal.siguiente
  109.     If IsNull(Nodotemporal.siguiente) Then
  110.     Else
  111.       Nodotemporal.siguiente.previo = Nodotemporal.previo  
  112.       Nodotemporal = Nodotemporal.siguiente.previo
  113.     Endif
  114.    
  115.     \'muestro la nueva lista de siguientes
  116.     TextLabel1.text = Nodotemporal.dato
  117.     TextLabelFrutasSiguen.text = Nodotemporal.VerLista()
  118.    
  119.   Endif
  120.  
  121. End
  122.  
  123. Public Sub ButtonPrevio_Click()
  124.  
  125.   If IsNull(Nodotemporal.previo) Then
  126.     TextLabelFrutasSiguen.text = "Primer Elemento"
  127.     Return
  128.   Endif
  129.   Nodotemporal = Nodotemporal.previo
  130.  
  131.   TextLabel1.text = Nodotemporal.dato
  132.   TextLabelFrutasSiguen.text = Nodotemporal.VerLista()
  133.  
  134. End
  135.  
  136. Public Sub Form_Close()
  137.  
  138.   \'Para no crear referencias circulares. borro todos los objetos
  139.  
  140.   \'me coloco al fina de la lista
  141.   While (Not (Nodotemporal.siguiente = Null))
  142.     Nodotemporal = Nodotemporal.siguiente
  143.   Wend
  144.  
  145.   While (Not (Nodotemporal.previo = Null))
  146.     Nodotemporal.siguiente = Null
  147.     Nodotemporal = Nodotemporal.previo
  148.    
  149.   Wend
  150.  
  151.   Nodotemporal.siguiente = Null
  152.  
  153. End
');