class ListaDoblementeEnlazada

Representa una lista doblemente enlazada

Attributes

head[R]
tail[R]

Public Class Methods

new() click to toggle source
# File lib/Dieta/lista_codigo.rb, line 64
def initialize
    @head = Node2.new
    @tail = @head
end

Public Instance Methods

each() { |aux| ... } click to toggle source

Hace un yield con cada elemento de la lista

# File lib/Dieta/lista_codigo.rb, line 141
def each
    aux= @head
    until aux[:next] == nil do
        yield aux[:value]
        aux=aux[:next]
    end
    if aux[:value] != nil then
        yield aux[:value]
    end
end
get_back() click to toggle source

Extrae el ultimo elemento de la lista

# File lib/Dieta/lista_codigo.rb, line 96
def get_back
    aux = nil
    if @tail[:value]==nil
        aux=nil
    else
        aux = @tail[:value]
        @tail = @tail[:prev]
        @tail[:next]=nil
    end
    if @tail==nil
        @tail = Node2.new
        @head = @tail
    end
    aux
end
insert_back(x) click to toggle source

Inserta al final de la lista

# File lib/Dieta/lista_codigo.rb, line 83
def insert_back(x)
    if @head[:value] == nil
        @head[:value]=x
    else 
        old_tail = @tail
        @tail = Node2.new(x, nil, old_tail)
        old_tail[:next] = @tail
    end 
    
    @tail[:value]
end
pop() click to toggle source

Extrae el primer elemento

# File lib/Dieta/lista_codigo.rb, line 127
def pop
    if @head!= nil then
        aux = @head[:value]
        @head = @head[:next]
    else
        aux=nil
    end
    if @head ==nil then 
        @head = Node2.new
    end
    aux
end
push(x) click to toggle source

Inserta al comienzo

# File lib/Dieta/lista_codigo.rb, line 70
def push(x)
    if @head[:value] == nil
        @head[:value]=x
        @tail=@head
    else
        aux= @head
        @head = Node2.new(x,aux)
        @head[:next][:prev]=@head
    end
    @head[:value]
end
size() click to toggle source

Devuelve el tamaƱo de la lista

# File lib/Dieta/lista_codigo.rb, line 113
def size
    count = 0
    if @head[:value] != nil then
        count=1
    end
    aux= @head
    until aux[:next] == nil do
        count+=1
        aux=aux[:next]
    end
    count
end