Class: ListaDE
Overview
Instance Attribute Summary collapse
-
#head ⇒ Object
readonly
Returns the value of attribute head.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#tail ⇒ Object
readonly
Returns the value of attribute tail.
Instance Method Summary collapse
- #each ⇒ Object
- #emisionesAnuales ⇒ Object
- #emisionesDiarias ⇒ Object
-
#extraerHead ⇒ Object
Extrae el primer valor de la lista.
- #extraerTail ⇒ Object
-
#initialize ⇒ ListaDE
constructor
Initialize de la lista, establece a nil la cabeza y la cola.
-
#insertarHead(value) ⇒ Object
Inserta el valor pasado a la lista por el head.
-
#insertarTail(value) ⇒ Object
Inserta el valor pasado a la lista por el tail.
- #usoTerreno ⇒ Object
Constructor Details
#initialize ⇒ ListaDE
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
#head ⇒ Object (readonly)
Returns the value of attribute head.
8 9 10 |
# File 'lib/listaDE.rb', line 8 def head @head end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
8 9 10 |
# File 'lib/listaDE.rb', line 8 def size @size end |
#tail ⇒ Object (readonly)
Returns the value of attribute tail.
8 9 10 |
# File 'lib/listaDE.rb', line 8 def tail @tail end |
Instance Method Details
#each ⇒ Object
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 |
#emisionesAnuales ⇒ Object
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 |
#emisionesDiarias ⇒ Object
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 |
#extraerHead ⇒ Object
Extrae el primer valor de la lista.
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 |
#extraerTail ⇒ Object
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
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
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 |
#usoTerreno ⇒ Object
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 |