class List

Contenedor de objetos

Modo de uso

lista = List.new
lista.insert(1)
lista.insert(2)
lista.last

Public Class Methods

new(head, tail) click to toggle source

Construye una lista con una cabeza y una cola

# File lib/FoodImpact/list.rb, line 15
def initialize (head, tail)
  @head_ = head
  @tail = tail
  @sz_ = 0
end

Public Instance Methods

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

Yield con cada elemento de la lista

# File lib/FoodImpact/list.rb, line 56
def each
  node = @head_
  while node != nil do
    yield node[:value]
    node = node[:next]
  end
end
first() click to toggle source

Extrae el primer objeto de la lista

# File lib/FoodImpact/list.rb, line 41
def first
  @head_[:value]
end
head() click to toggle source

Devuelve head

# File lib/FoodImpact/list.rb, line 46
def head
  @head_
end
insert(object) click to toggle source

Inserta en la lista un nodo en la última posición

# File lib/FoodImpact/list.rb, line 22
def insert(object)
  node = Node.new(object, nil, nil)
  if @sz_ == 0
    @head_ = node
    @tail_ = node
  else
    @tail_[:next] = node
    node[:prev] = @tail_
    @tail_ = node
  end
  @sz_+=1
end
last() click to toggle source

Extrae el último objeto de la lista

# File lib/FoodImpact/list.rb, line 36
def last
  @tail_[:value]
end
tail() click to toggle source

Devuelve tail

# File lib/FoodImpact/list.rb, line 51
def tail
  @tail_
end