Class: Lista
Instance Attribute Summary collapse
-
#head ⇒ Object
Includes the module Enumerable It have tres values, head of the list, queue of the list and size of the list.
-
#queue ⇒ Object
Includes the module Enumerable It have tres values, head of the list, queue of the list and size of the list.
-
#tamanio ⇒ Object
Includes the module Enumerable It have tres values, head of the list, queue of the list and size of the list.
Instance Method Summary collapse
-
#convertirArray(lista) ⇒ Object
return array param lista.
-
#each ⇒ Object
return node.
-
#empty ⇒ Object
return true or false.
-
#initialize ⇒ Object
constructor
Lista type of the class.
-
#insert_head(nodo) ⇒ Object
Head of the node.
-
#insert_plus(nodos, index) ⇒ Object
Nodo.
-
#insert_queue(nodo) ⇒ Object
Queue of the node.
-
#ordenandoEach(lista) ⇒ Object
return array param lista.
- #ordenandoSort(lista) ⇒ Object
-
#ordenarArray(lista) ⇒ Object
return array param lista.
-
#pop_head ⇒ Object
Head of the list.
-
#pop_queue ⇒ Object
Queue of the list.
-
#to_s ⇒ String
The resulting of join all the information, value, next and previous.
Constructor Details
#initialize ⇒ Object
Returns Lista type of the class.
18 19 20 21 22 |
# File 'lib/prct06/lista.rb', line 18 def initialize @head = nil @queue = nil @tamanio = 0 end |
Instance Attribute Details
#head ⇒ Object
Includes the module Enumerable It have tres values, head of the list, queue of the list and size of the list
13 14 15 |
# File 'lib/prct06/lista.rb', line 13 def head @head end |
#queue ⇒ Object
Includes the module Enumerable It have tres values, head of the list, queue of the list and size of the list
13 14 15 |
# File 'lib/prct06/lista.rb', line 13 def queue @queue end |
#tamanio ⇒ Object
Includes the module Enumerable It have tres values, head of the list, queue of the list and size of the list
13 14 15 |
# File 'lib/prct06/lista.rb', line 13 def tamanio @tamanio end |
Instance Method Details
#convertirArray(lista) ⇒ Object
return array param lista
135 136 137 |
# File 'lib/prct06/lista.rb', line 135 def convertirArray(lista) lista.map{ |y| y} end |
#each ⇒ Object
return node
202 203 204 205 206 207 208 |
# File 'lib/prct06/lista.rb', line 202 def each aux = @head while aux != nil yield aux.valor aux = aux.siguiente end end |
#empty ⇒ Object
return true or false
193 194 195 196 197 198 199 |
# File 'lib/prct06/lista.rb', line 193 def empty if tamanio == 0 true else false end end |
#insert_head(nodo) ⇒ Object
Returns head of the node.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/prct06/lista.rb', line 26 def insert_head(nodo) if empty nodo[:siguiente] = nil nodo[:anterior] = nil @head = nodo @queue = nodo else nodo[:siguiente] = @head @head[:anterior] = nodo nodo[:anterior] = nil @head = nodo end @tamanio = @tamanio + 1 end |
#insert_plus(nodos, index) ⇒ Object
Returns nodo.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/prct06/lista.rb', line 65 def insert_plus(nodos, index) #si el indice es 1, insertara por la cabeza if(index == 1) for i in 0..(nodos.length-1) insert_head(nodos[i]) end end #Si el indice es 2, insertara por la cola else if(index == 2) for i in 0..(nodos.length-1) insert_queue(nodos[i]) end end end |
#insert_queue(nodo) ⇒ Object
Returns queue of the node.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/prct06/lista.rb', line 46 def insert_queue(nodo) if empty nodo[:siguiente] = nil nodo[:anterior] = nil @head = nodo @queue = nodo else nodo[:siguiente] = nil nodo[:anterior] = @queue @queue[:siguiente] = nodo @queue = nodo end @tamanio = @tamanio + 1 end |
#ordenandoEach(lista) ⇒ Object
return array param lista
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/prct06/lista.rb', line 163 def ordenandoEach(lista) auxiliar = lista.convertirArray(lista) indice = 0 auxiliar.each do |x| auxiliar.each do |y| if (indice < auxiliar.length-1) if (auxiliar[indice] > auxiliar[indice+1]) temporal = auxiliar[indice] auxiliar[indice] = auxiliar[indice+1] auxiliar[indice+1] = temporal end end indice = indice+1 end indice = 0 end return auxiliar end |
#ordenandoSort(lista) ⇒ Object
185 186 187 188 |
# File 'lib/prct06/lista.rb', line 185 def ordenandoSort(lista) auxiliar = lista.convertirArray(lista) auxiliar.sort end |
#ordenarArray(lista) ⇒ Object
return array param lista
143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/prct06/lista.rb', line 143 def ordenarArray(lista) auxiliar = lista.convertirArray(lista) for i in 0..(auxiliar.length)do for j in 0..(auxiliar.length-2) do if auxiliar[j] > auxiliar[j+1] temporal = auxiliar[j] auxiliar[j] = auxiliar[j+1] auxiliar[j+1] = temporal end end end return auxiliar end |
#pop_head ⇒ Object
Returns head of the list.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/prct06/lista.rb', line 82 def pop_head if !empty if @head == @queue aux = @head @head = nil @queue = nil else aux = @head @head = @head.siguiente @head[:anterior] = nil end @tamanio = @tamanio -1 aux end end |
#pop_queue ⇒ Object
Returns queue of the list.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/prct06/lista.rb', line 102 def pop_queue if !empty if @queue == @head aux = @queue @head = nil @queue = nil else aux = @queue @queue =aux.anterior @queue[:siguiente] = nil end @tamanio = @tamanio - 1 aux end end |
#to_s ⇒ String
Returns the resulting of join all the information, value, next and previous.
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/prct06/lista.rb', line 120 def to_s aux = @head s = "" while aux.siguiente != nil s += aux.valor.to_s + "\n" aux = aux.siguiente end s += aux.valor.to_s end |