class C_LinkedList

Attributes

a_fin[RW]
a_inicio[RW]

Public Class Methods

new() click to toggle source
# File lib/menus/LinkedList.rb, line 5
def initialize()
    @a_inicio = nil
    @a_fin = nil
end

Public Instance Methods

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

— Definición del Método Mixins Enumerable —

# File lib/menus/LinkedList.rb, line 12
def each
    nodo = @a_inicio
    while nodo != nil
        yield nodo.value
        nodo = nodo.next
    end
end
empty() click to toggle source

— Método que comprueba si la lista esta vacia —

# File lib/menus/LinkedList.rb, line 22
def empty
    if ((@a_inicio == nil) && (a_fin == nil))
        true
    else
        false
    end
end
extract_back() click to toggle source

— Método para extraer elementos desde el final de la lista —

# File lib/menus/LinkedList.rb, line 85
def extract_back
    if (empty == true)
        puts "La lista en el metodo extract_back esta vacia"
    else
        aux = @a_fin
        @a_fin = @a_fin.previus
        aux
    end
end
extract_front() click to toggle source

— Método para extraer elementos desde el inicio de la lista —

# File lib/menus/LinkedList.rb, line 39
def extract_front
    if (empty == true)
        puts "La lista en el metodo extract_front esta vacia"
    else
        aux = @a_inicio
        @a_inicio = @a_inicio.next
        aux
    end
end
insert_first(value) click to toggle source

— Método para insertar el primer elemento de la lista —

# File lib/menus/LinkedList.rb, line 32
def insert_first(value)
    @a_fin = value
    @a_inicio = value
end
mostrar_fin_inicio() click to toggle source
# File lib/menus/LinkedList.rb, line 113
def mostrar_fin_inicio
    if (empty == true)
        puts "--- La lista esta vacia ---"
    else
        puts
        puts "--- LA LISTA DEL FINAL AL PRINCIPIO ES, "
        puts

        aux = @a_fin
        puts @a_fin.value

        while aux.previus do
            puts "--------------"
            aux = aux.previus
            puts aux.value          
        end
    end
end
mostrar_inicio_fin() click to toggle source
# File lib/menus/LinkedList.rb, line 66
def mostrar_inicio_fin
    if (empty == true)
        puts "--- La lista esta vacia ---"
    else
        puts
        puts "--- LA LISTA DEL PRINCIPIO AL FINAL ES, "
        puts
        aux = @a_inicio
        puts @a_inicio.value
        while aux.next do
            puts "--------------"
            aux = aux.next
            puts aux.value
        end
    end
end
push_back(nodo) click to toggle source

— Metodo para insertar un elemento a la lista por el final —

# File lib/menus/LinkedList.rb, line 97
def push_back(nodo)
    nodo.each do |value|
        if (empty == true)
            puts "---- Metodo INSERTAR_FINAL, La lista esta vacia ----"
            insert_first(value)
        else
            aux = @a_fin
            @a_fin = value
            aux.next = @a_fin
            @a_fin.previus = aux
        end
    end
end
push_front(nodo) click to toggle source

— Método para insertar un elemento a la lista por el inicio —

# File lib/menus/LinkedList.rb, line 51
def push_front(nodo)
    nodo.each do |value|
        if (empty == true)
            insert_first(value)
        else
            aux = @a_inicio
            @a_inicio = value
            aux.previus = @a_inicio
            @a_inicio.next = aux
        end
    end
end