class Dl_linked_list

Constants

Node

Attributes

inicio[R]
tail[R]

Public Class Methods

new(&block) click to toggle source
# File lib/dieta/dl_list.rb, line 5
def initialize(&block)
                @inicio= nil
                @tail= nil
if(block_given?)
        instance_eval(&block)
end            
end

Public Instance Methods

elemento(options) click to toggle source
# File lib/dieta/dl_list.rb, line 12
def elemento(options)
        insert_inicio(options[:data])
end
extract_final() click to toggle source
# File lib/dieta/dl_list.rb, line 47
def extract_final
        if(@inicio!=nil)
        temp=@tail[:value]
        @tail=@tail[:prev]
        @tail[:next]=nil
        end
end
extract_inicio() click to toggle source
# File lib/dieta/dl_list.rb, line 39
def extract_inicio
        if(@inicio!=nil)
        temp= @inicio[:value]
        @inicio=@inicio[:next]
        @inicio[:prev]=nil
        temp
        end
end
insert_final(data) click to toggle source
# File lib/dieta/dl_list.rb, line 15
def insert_final(data)
                if(@inicio==nil && @tail==nil)
                        aux=Node.new(data,nil,nil)
                        @inicio= aux
                        @tail = @inicio
                else
                aux=Node.new(data,nil,@tail)
                @tail[:next]=aux
                @tail=aux

                end
end
insert_inicio(data) click to toggle source
# File lib/dieta/dl_list.rb, line 27
def insert_inicio(data)
                if(@inicio==nil && @tail==nil)
                        aux=Node.new(data,nil,nil)
                        @inicio=aux
                        @tail = @inicio
                else
                        aux=Node.new(data,nil,@inicio)
                        @inicio[:prev]=aux
                        @inicio=aux
                end
end
to_s() click to toggle source
# File lib/dieta/dl_list.rb, line 54
def to_s
        temp = @inicio
        cont= 1
        string = "" 
        while(temp!=nil)
                string+="Valor numero #{cont}) Equivale a #{temp[:value]}\n"
                temp=temp[:next]
                cont+=1
        end

        string
end