class Dieta::Lista

Attributes

cabecera[R]
cola[R]
longitud[R]

Public Class Methods

new() click to toggle source
# File lib/dieta/lista.rb, line 8
def initialize
    @cabecera = nil
    @cola = nil
    @longitud = 0
end

Public Instance Methods

each() { |valor| ... } click to toggle source
# File lib/dieta/lista.rb, line 14
def each
      temp = @cabecera
      while temp != nil do
          yield temp.valor
          temp = temp.siguiente
      end
end
get() click to toggle source
# File lib/dieta/lista.rb, line 60
def get
  unless @cola.nil?
    node = @cola
    @cola = @cola.anterior
    @cola.siguiente = nil
    node.valor
  end
end
get_e(indice) click to toggle source
# File lib/dieta/lista.rb, line 69
def get_e(indice)
    temp = @cabecera
    count = 0
    while count < indice - 1 do
        temp = temp.siguiente
        count += 1
    end
    temp.valor
end
pop() click to toggle source
# File lib/dieta/lista.rb, line 51
def pop
    unless @cabecera.nil?
        node = @cabecera
        @cabecera = @cabecera.siguiente
        @cabecera.anterior = nil
        node.valor
    end
end
push(valores) click to toggle source
# File lib/dieta/lista.rb, line 22
def push(valores)
    if valores.instance_of? Array
        valores.each do |valor|
            node = Node.new(valor, nil, nil)
            if @cabecera.nil?
                @cabecera = node
                @cola = node
            else
                node = Node.new(valor, nil, @cola)
                @cola.siguiente = node
                @cola = node
            end
            @longitud += 1
        end
    else
        node = Node.new(valores, nil, nil)
        if @cabecera.nil?
            @cabecera = node
            @cola = node
        else
            node = Node.new(valores, nil, @cola)
            @cola.next = node
            @cola = node
        end
        @longitud += 1
      end
    @cola.valor
end
set_e(indice, val) click to toggle source
# File lib/dieta/lista.rb, line 79
def set_e(indice, val)
    temp = @cabecera
    count = 0
    while count < indice - 1 do
        temp = temp.siguiente
        count += 1
    end
    temp.valor = val
end
to_s() click to toggle source
# File lib/dieta/lista.rb, line 89
def to_s
  count = 2
  output = @cabecera.valor.to_s
  while count < @longitud - 1 do
    obj = get_e(count)
    output += obj.to_s
    count += 1
  end
  output
end