Class: ListaDE

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/listaDE.rb

Overview

Author:

  • Juan Martínez

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeListaDE

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



11
12
13
14
15
# File 'lib/listaDE.rb', line 11

def initialize()
    @head = nil
    @tail = nil
    @size = 0
end

Instance Attribute Details

#headObject (readonly)

Returns the value of attribute head.



8
9
10
# File 'lib/listaDE.rb', line 8

def head
  @head
end

#sizeObject (readonly)

Returns the value of attribute size.



8
9
10
# File 'lib/listaDE.rb', line 8

def size
  @size
end

#tailObject (readonly)

Returns the value of attribute tail.



8
9
10
# File 'lib/listaDE.rb', line 8

def tail
  @tail
end

Instance Method Details

#eachObject



105
106
107
108
109
110
111
# File 'lib/listaDE.rb', line 105

def each
    nodo=@tail
    while nodo != nil
        yield nodo.value
        nodo = nodo.next
    end
end

#emisionesAnualesObject



88
89
90
91
92
93
94
95
# 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

#emisionesDiariasObject



80
81
82
83
84
85
86
# 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

#extraerHeadObject

Extrae el primer valor de la lista.

Returns:



54
55
56
57
58
59
60
61
62
63
64
65
# 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

#extraerTailObject



67
68
69
70
71
72
73
74
75
76
77
78
# 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) ⇒ Object

Inserta el valor pasado a la lista por el head

Parameters:

  • value

Returns:



21
22
23
24
25
26
27
28
29
30
31
32
# 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) ⇒ Object

Inserta el valor pasado a la lista por el tail

Parameters:

  • value

Returns:



38
39
40
41
42
43
44
45
46
47
48
49
# 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

#usoTerrenoObject



97
98
99
100
101
102
103
# 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