class List::List

Attributes

fin[RW]
inicio[RW]

Public Class Methods

new() click to toggle source
# File lib/Bibliografia/list.rb, line 15
def initialize()
    
    @inicio= nil
    @fin = nil
end

Public Instance Methods

each() { |nil| ... } click to toggle source
# File lib/Bibliografia/list.rb, line 72
def each
    aux = @inicio
    if (@inicio == nil and @fin == nil)
            
            yield nil
            
        elsif (@inicio == @fin)
            
            yield @inicio.value
            
        else
            while(aux != nil)
                yield aux.value  
                aux = aux.next 
            end
    end
end
empty() click to toggle source
# File lib/Bibliografia/list.rb, line 122
def empty() #Comprueba si la lista esta vacia
    
    if(@inicio == nil)
        return true
    else
        return false
    end
    
end
extract_beg() click to toggle source
# File lib/Bibliografia/list.rb, line 22
def extract_beg()
    
    if (@inicio != nil)
        aux= @inicio
        @inicio= @inicio.next
        return aux
    else
        return nil
    end
end
extract_end() click to toggle source
# File lib/Bibliografia/list.rb, line 93
def extract_end() #Extraer al final
    if(@fin != nil)
        aux= @fin
        @fin= @fin.prev
        return aux
    else
        return nil
    end
    
end
insert_end(valor) click to toggle source
# File lib/Bibliografia/list.rb, line 57
def insert_end(valor)
    
    nodo = Node.new(nil, valor,nil)
    if(@fin == nil)
        @fin = nodo
        @inicio = nodo
    else
        aux = @fin
        @fin = nodo
        @fin.prev = aux
        aux.next = @fin
    end  
end
insert_multiple_beg(nodos) click to toggle source
# File lib/Bibliografia/list.rb, line 107
def insert_multiple_beg(nodos) #insertar multiple al principio
    nodos.each do |element|
        insert_single_beg(element)
    end
end
insert_multiple_end(nodos) click to toggle source
# File lib/Bibliografia/list.rb, line 113
def insert_multiple_end(nodos) #Insertar multiple al final
    nodos.each do |element|
        insert_single_end(element)
    end
end
insert_single_beg(valor) click to toggle source
# File lib/Bibliografia/list.rb, line 37
def insert_single_beg(valor)
    
    nodo = Node.new(nil, valor, nil)
    
    if (@inicio == nil)
        @inicio = nodo
        @fin = nodo
    else
        aux = @inicio
        @inicio = nodo
        @inicio.next = aux
        aux.prev = @inicio
        
    end
end
to_s() click to toggle source
# File lib/Bibliografia/list.rb, line 133
def to_s()
    
    lista_ref = []
    index= 0
    while(@inicio != nil)
       lista_ref1= @inicio.value.to_s()
       lista_ref[index]= lista_ref1
        @inicio= @inicio.next
        index += 1
    end
    lista_ref
end