class Lista

Attributes

head[RW]
lastnext[RW]
puntero[RW]

Public Class Methods

new() click to toggle source
# File lib/nodelist/list.rb, line 6
def initialize()
  @head = nil
  @lastnext = nil
end

Public Instance Methods

add(*args) click to toggle source
# File lib/nodelist/list.rb, line 39
def add(*args)
  args.each do |value|
    if @head == nil then
      @head = Node.new(value, nil, nil)
      @lastnext = @head
    else
      last = Node.new(value, nil, @lastnext)
      last.father = @lastnext
      @lastnext.next = last
      @lastnext = last
    end
  end
end
add_s(value) click to toggle source
# File lib/nodelist/list.rb, line 28
def add_s(value) 
    if @head == nil then
      @head = Node.new(value, nil, nil)
      @lastnext = @head
    else
      last = Node.new(value, nil, @lastnext)
      last.father = @lastnext
      @lastnext.next = last
      @lastnext = last
    end
end
each() { |value| ... } click to toggle source
# File lib/nodelist/list.rb, line 10
def each
 aux = @head
 while aux != nil
     yield aux.value
     aux = aux.next
 end
end
first() click to toggle source
# File lib/nodelist/list.rb, line 52
def first
  if @head != nil then
    aux = @head.value
    @head = @head.next
    return aux
  else
    return -1
  end
end
reverse() click to toggle source
# File lib/nodelist/list.rb, line 21
def reverse
  list = Array.new
  @head.reverse{|x| list.push(x.value)}
  @head = nil
  @lastnext = nil
  list.each{|x| self.add(x)}
end
reverse_each() { |value;| ... } click to toggle source
# File lib/nodelist/list.rb, line 17
def reverse_each
    @head.each {yield @lastnext.value; @lastnext=@lastnext.father} if @lastnext != nil
end
to_a() click to toggle source
# File lib/nodelist/list.rb, line 64
def to_a
  a_value = Array.new
  pointer = @head
  while pointer.next != nil do
    a_value.push(pointer.value)
    pointer = pointer.next
  end
  a_value.push(pointer.value)
  a_value.to_s
end
to_s() click to toggle source
# File lib/nodelist/list.rb, line 61
def to_s
  "#{@head}"
end