class ListaDE

@author Juan Martínez

Attributes

head[R]
size[R]
tail[R]

Public Class Methods

new() click to toggle source

Initialize de la lista, establece a nil la cabeza y la cola

# File lib/listaDE.rb, line 11
def initialize()
    @head = nil
    @tail = nil
    @size = 0
end

Public Instance Methods

each() { |value| ... } click to toggle source
# File lib/listaDE.rb, line 105
def each
      nodo=@tail
      while nodo != nil
          yield nodo.value
          nodo = nodo.next
      end
  end
emisionesAnuales() click to toggle source
# File lib/listaDE.rb, line 88
def emisionesAnuales
  emisiones = 0
  for i in 0..self.size-1
    emisiones += self.extraerHead.value.gei
  end
  emisiones = emisiones * 365
  return emisiones
end
emisionesDiarias() click to toggle source
# File lib/listaDE.rb, line 80
def emisionesDiarias
  emisiones = 0
  for i in 0..self.size-1
    emisiones += self.extraerHead.value.gei
  end
  return emisiones
end
extraerHead() click to toggle source

Extrae el primer valor de la lista.

@return

# File lib/listaDE.rb, line 54
 def extraerHead ()
      extraer = @head
      headActual = @head.prev
      @head = headActual
      if headActual == nil
          @tail = nil
      else
          @head.next = nil
      end
      @size-=1
      return extraer
end
extraerTail() click to toggle source
# File lib/listaDE.rb, line 67
def extraerTail()
      extraer = @tail
      tailActual = @tail.next
      @tail = tailActual
      if tailActual == nil
          @head = nil
      else
          @tail.prev = nil
      end
      @size-=1
      return extraer
  end
insertarHead(value) click to toggle source

Inserta el valor pasado a la lista por el head

@param value @return

# File lib/listaDE.rb, line 21
def insertarHead(value)
    nodo = Node.new(value)
    if @head == nil and @tail == nil
        @head = nodo
        @tail = nodo
    else
        @head.next = nodo
        nodo.prev = @head
        @head = nodo
    end
    @size+=1
end
insertarTail(value) click to toggle source

Inserta el valor pasado a la lista por el tail

@param value @return

# File lib/listaDE.rb, line 38
 def insertarTail(value)
    nodo = Node.new(value)
    if @head == nil and @tail == nil
        @head = nodo
        @tail = nodo
    else
        @tail.prev = nodo
        nodo.next = @tail
        @tail = nodo
    end
    @size+=1
end
usoTerreno() click to toggle source
# File lib/listaDE.rb, line 97
def usoTerreno
  uso_terreno = 0
  for i in 0..self.size-1
    uso_terreno += self.extraerHead.value.terreno
  end
  return uso_terreno
end