Class: Lista
Direct Known Subclasses
Instance Attribute Summary collapse
-
#fin ⇒ Object
Returns the value of attribute fin.
-
#inicio ⇒ Object
Returns the value of attribute inicio.
-
#tamanio ⇒ Object
Returns the value of attribute tamanio.
Instance Method Summary collapse
- #each ⇒ Object
-
#extraerPrimerElemento ⇒ Object
Extrae el primer elemento de la lista.
-
#extraerUltimoElemento ⇒ Object
Extrae el Ășltimo elemento de la lista.
-
#initialize ⇒ Lista
constructor
Constructor.
-
#insertar_final(*a_elemento) ⇒ Object
Inserta uno o varios elementos por el final (cabeza).
-
#insertar_inicio(*a_elemento) ⇒ Object
Inserta uno o varios elementos por el principio (cola).
-
#mostar_fin_inicio ⇒ Object
Muestra la lista desde el final hasta el principio.
-
#mostar_inicio_fin ⇒ Object
Muestra la lista desde el inicio hasta el final.
Constructor Details
Instance Attribute Details
#fin ⇒ Object
Returns the value of attribute fin.
4 5 6 |
# File 'lib/referencia/lista.rb', line 4 def fin @fin end |
#inicio ⇒ Object
Returns the value of attribute inicio.
4 5 6 |
# File 'lib/referencia/lista.rb', line 4 def inicio @inicio end |
#tamanio ⇒ Object
Returns the value of attribute tamanio.
4 5 6 |
# File 'lib/referencia/lista.rb', line 4 def tamanio @tamanio end |
Instance Method Details
#each ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/referencia/lista.rb', line 76 def each aux =self.inicio while aux.next != nil do yield aux.value aux = aux.next end end |
#extraerPrimerElemento ⇒ Object
Extrae el primer elemento de la lista
65 66 67 68 69 |
# File 'lib/referencia/lista.rb', line 65 def extraerPrimerElemento @tamanio = @tamanio-1 @inicio = @inicio.next end |
#extraerUltimoElemento ⇒ Object
Extrae el Ășltimo elemento de la lista
71 72 73 74 75 |
# File 'lib/referencia/lista.rb', line 71 def extraerUltimoElemento @tamanio = @tamanio-1 @fin = @fin.previus @fin.next = nil end |
#insertar_final(*a_elemento) ⇒ Object
Inserta uno o varios elementos por el final (cabeza)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/referencia/lista.rb', line 12 def insertar_final(*a_elemento) a_elemento.each do |elemento| a_aux = Node.new(nil) a_aux.value = elemento if(@inicio.value == nil) @inicio = a_aux @fin = a_aux else a_aux.previus = @fin @fin.next = a_aux @fin = a_aux end @tamanio=@tamanio+1 end end |
#insertar_inicio(*a_elemento) ⇒ Object
Inserta uno o varios elementos por el principio (cola)
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/referencia/lista.rb', line 29 def insertar_inicio(*a_elemento) a_elemento.each do |elemento| a_aux = Node.new(nil) a_aux.value=elemento if(@inicio.value == nil) @inicio = a_aux @fin = a_aux @tamanio=@tamanio+1 else a_aux.next = @inicio @inicio.previus = a_aux @inicio = a_aux end @tamanio = @tamanio+1 end end |
#mostar_fin_inicio ⇒ Object
Muestra la lista desde el final hasta el principio
56 57 58 59 60 61 62 63 |
# File 'lib/referencia/lista.rb', line 56 def mostar_fin_inicio aux = @fin p @fin.value while aux.previus do aux = aux.previus p aux.value end end |
#mostar_inicio_fin ⇒ Object
Muestra la lista desde el inicio hasta el final
47 48 49 50 51 52 53 54 |
# File 'lib/referencia/lista.rb', line 47 def mostar_inicio_fin aux = @inicio p @inicio.value while aux.next do aux = aux.next p aux.value end end |