Class: ListaDobleEnlazada

Inherits:
Object
  • Object
show all
Includes:
Comparable, Enumerable
Defined in:
lib/alu0100406580_nutricion/listaDobleEnlazada.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeListaDobleEnlazada

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

#cabezaObject

Returns the value of attribute cabeza.



27
28
29
# File 'lib/alu0100406580_nutricion/listaDobleEnlazada.rb', line 27

def cabeza
  @cabeza
end

#colaObject

Returns the value of attribute cola.



27
28
29
# File 'lib/alu0100406580_nutricion/listaDobleEnlazada.rb', line 27

def cola
  @cola
end

#tamañoObject

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

#eachObject



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

#extraerDelanteObject



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

#extraerDetrasObject



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

Returns:

  • (Boolean)


88
89
90
# File 'lib/alu0100406580_nutricion/listaDobleEnlazada.rb', line 88

def is_empty?
    return self.tamaño.zero?
end

#to_sObject



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