Class: Lista
Overview
Clase Lista.
Instance Method Summary collapse
-
#each ⇒ Object
5.
-
#empty? ⇒ Boolean
1.
-
#extract_head ⇒ Object
4.
-
#extract_tail ⇒ Object
3.
-
#initializate ⇒ Object
0.
-
#insert_head(value) ⇒ Object
2.
-
#insert_tail(value) ⇒ Object
2.
-
#ordenacion_Each ⇒ Object
7.
-
#ordenacion_For ⇒ Object
6.
-
#to_s ⇒ Object
8.
Instance Method Details
#each ⇒ Object
-
METODO PARA QUE UNA LISTA SEA ENUMERABLE
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/nutricion/lista_code.rb', line 98 def each nodo = @head while(nodo != nil) yield nodo.value nodo = nodo.prev end end |
#empty? ⇒ Boolean
-
METODO PARA COMPROBAR QUE NO ESTA VACIO
17 18 19 20 21 22 23 24 25 |
# File 'lib/nutricion/lista_code.rb', line 17 def empty?() if @head == nil return true else return false end end |
#extract_head ⇒ Object
-
METODO PARA EXTRAER POR LA CABEZA
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/nutricion/lista_code.rb', line 79 def extract_head() node = @head @head = @head.prev if (@head == nil) @tail = nil else @head.next = nil end node.prev = nil node.next =nil return node.value end |
#extract_tail ⇒ Object
-
METODO PARA EXTRAER POR LA COLA
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/nutricion/lista_code.rb', line 59 def extract_tail() node = @tail @tail = @tail.next if (@tail == nil) @head = nil else @tail.prev = nil end node.prev = nil node.next =nil return node.value end |
#initializate ⇒ Object
-
METODO INITIALIZE
12 13 14 |
# File 'lib/nutricion/lista_code.rb', line 12 def initializate() @head = @tail = nil end |
#insert_head(value) ⇒ Object
-
METODO PARA AÑADIR POR LA CABEZA
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/nutricion/lista_code.rb', line 29 def insert_head(value) node = Node.new(value) if (@head == nil) @head = @tail = node else node.prev = @head @head.next = node @head = node end end |
#insert_tail(value) ⇒ Object
-
METODO PARA AÑADIR POR LA COLA
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/nutricion/lista_code.rb', line 45 def insert_tail(value) node = Node.new(value) if (@tail == nil) @head = @tail = node else node.next = @tail @tail.prev = node @tail = node end end |
#ordenacion_Each ⇒ Object
-
MÉTODO PARA ORDENAR UNA LISTA USANDO EL EACH
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/nutricion/lista_code.rb', line 129 def ordenacion_Each () dato = self.map { |x| x} indice = 0 dato.each do |x| dato.each do |y| if (indice < dato.length-1) if (dato[indice] > dato[indice+1]) temporal = dato[indice] dato[indice] = dato[indice+1] dato[indice+1] = temporal end end indice = indice+1 end indice = 0 end dato end |
#ordenacion_For ⇒ Object
-
MÉTODO PARA ORDENAR UNA LISTA USANDO EL FOR
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/nutricion/lista_code.rb', line 110 def ordenacion_For () dato = self.map { |x| x} for i in 0..(dato.length) do for j in 0..(dato.length-2) do if(dato[j] > dato[j+1]) temporal = dato[j] dato[j] = dato[j+1] dato[j+1] = temporal end end end dato end |
#to_s ⇒ Object
-
METODO PARA MOSTRAR LOS DATOS POR PANTALLA
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/nutricion/lista_code.rb', line 152 def to_s if (@head != nil) nodito = @head @salida = nodito.value if ( nodito.prev != nil ) @salida += ", " end while (nodito.prev != nil) do nodito = nodito.prev @salida += nodito.value if ( nodito.prev != nil ) @salida += ", " end end "#{@salida}" end end |