class BiblioGem::List

Attributes

head[RW]
size[RW]
tail[RW]

Public Class Methods

new(*args) click to toggle source
# File lib/biblio_gem/list.rb, line 7
def initialize(*args)
        @head = @tail = nil
        @size = 0
        self.push_back(*args) if(args!=nil)
        
end

Public Instance Methods

each() { |value| ... } click to toggle source
# File lib/biblio_gem/list.rb, line 54
def each
        aux = @head
        while aux!=nil
                yield aux.value
                aux = aux.next
        end
end
pop_back() click to toggle source
# File lib/biblio_gem/list.rb, line 46
def pop_back
        return false if @size==0
        pos = @tail
        @tail = pos.prev
        @size -= 1
        pos.value
end
pop_front() click to toggle source
# File lib/biblio_gem/list.rb, line 38
def pop_front
        return false if @size==0
        pos = @head
        @head = pos.next
        @size -= 1
        pos.value
end
push_back(*args) click to toggle source
# File lib/biblio_gem/list.rb, line 14
def push_back(*args)
        args.each do |value|
                if(@tail==nil)                                                                      #La cola esta vacia
                        @tail = @head = Node.new(:value => value)
                else
                        @tail.next = Node.new(:value => value)
                        @tail = @tail.next
                end
                @size += 1
        end
end
push_front(*args) click to toggle source
# File lib/biblio_gem/list.rb, line 26
def push_front(*args)
        args.each do |value|
                if(@head==nil)                                                                      #La cola esta vacia
                        @head = @tail = Node.new(:value => value)
                else
                        @head.prev = Node.new(:value => value)
                        @head = @head.prev
                end
                @size += 1
        end
end