Class: ListaDobleEnlazada
- Inherits:
-
Object
- Object
- ListaDobleEnlazada
- Includes:
- Comparable, Enumerable
- Defined in:
- lib/alu0100406580_nutricion/listaDobleEnlazada.rb
Instance Attribute Summary collapse
-
#cabeza ⇒ Object
Returns the value of attribute cabeza.
-
#cola ⇒ Object
Returns the value of attribute cola.
-
#tamaño ⇒ Object
Returns the value of attribute tamaño.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #each ⇒ Object
- #extraerDelante ⇒ Object
- #extraerDetras ⇒ Object
-
#initialize ⇒ ListaDobleEnlazada
constructor
A new instance of ListaDobleEnlazada.
- #insertaAdelante(valor) ⇒ Object
- #insertaAtras(valor) ⇒ Object
- #is_empty? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ ListaDobleEnlazada
Returns a new instance of ListaDobleEnlazada.
30 31 32 33 34 |
# File 'lib/alu0100406580_nutricion/listaDobleEnlazada.rb', line 30 def initialize() @cabeza = nil @cola = nil @tamaño = 0 end |
Instance Attribute Details
#cabeza ⇒ Object
Returns the value of attribute cabeza.
27 28 29 |
# File 'lib/alu0100406580_nutricion/listaDobleEnlazada.rb', line 27 def cabeza @cabeza end |
#cola ⇒ Object
Returns the value of attribute cola.
27 28 29 |
# File 'lib/alu0100406580_nutricion/listaDobleEnlazada.rb', line 27 def cola @cola end |
#tamaño ⇒ Object
Returns the value of attribute tamaño.
27 28 29 |
# File 'lib/alu0100406580_nutricion/listaDobleEnlazada.rb', line 27 def tamaño @tamaño end |
Instance Method Details
#<=>(other) ⇒ Object
109 110 |
# File 'lib/alu0100406580_nutricion/listaDobleEnlazada.rb', line 109 def <=>(other) end |
#each ⇒ Object
112 113 114 115 116 117 118 119 |
# File 'lib/alu0100406580_nutricion/listaDobleEnlazada.rb', line 112 def each nodoAux = Node.new(nil,nil,nil) nodoAux = @cabeza while(nodoAux != nil) yield nodoAux["value"] nodoAux = nodoAux["next"] end end |
#extraerDelante ⇒ Object
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/alu0100406580_nutricion/listaDobleEnlazada.rb', line 66 def extraerDelante if(self.tamaño == 0) return "Lista Vacía" else nodoAux = @cabeza @cabeza = @cabeza["next"] @tamaño = @tamaño - 1 return nodoAux["value"] end end |
#extraerDetras ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/alu0100406580_nutricion/listaDobleEnlazada.rb', line 77 def extraerDetras if(self.tamaño == 0) return "Lista Vacía" else nodoAux = @cola @cola = @cola["prev"] @tamaño = @tamaño - 1 return nodoAux["value"] end end |
#insertaAdelante(valor) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/alu0100406580_nutricion/listaDobleEnlazada.rb', line 36 def insertaAdelante(valor) nodo = Node.new(valor,nil,nil) if (self.tamaño == 0) @cabeza = nodo @cola = nodo else nodo["next"] = @cabeza @cabeza.prev = nodo @cabeza = nodo end @tamaño = @tamaño + 1 end |
#insertaAtras(valor) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/alu0100406580_nutricion/listaDobleEnlazada.rb', line 51 def insertaAtras(valor) nodo = Node.new(valor,nil,nil) if (self.tamaño == 0) @cabeza = nodo @cola = nodo else nodo["prev"] = @cola @cola.next = nodo @cola = nodo end @tamaño = @tamaño + 1 end |
#is_empty? ⇒ Boolean
88 89 90 |
# File 'lib/alu0100406580_nutricion/listaDobleEnlazada.rb', line 88 def is_empty? return self.tamaño.zero? end |
#to_s ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/alu0100406580_nutricion/listaDobleEnlazada.rb', line 92 def to_s nodoAux = Node.new(nil,nil,nil) nodoAux = @cabeza arr = [] if (self.tamaño == 0) return "Lista Vacía" else while(nodoAux != nil) arr.push nodoAux["value"] nodoAux = nodoAux["next"] end return arr end end |