Class: C_LinkedList
- Inherits:
-
Object
- Object
- C_LinkedList
- Includes:
- Enumerable
- Defined in:
- lib/menus/LinkedList.rb
Instance Attribute Summary collapse
-
#a_fin ⇒ Object
Returns the value of attribute a_fin.
-
#a_inicio ⇒ Object
Returns the value of attribute a_inicio.
Instance Method Summary collapse
-
#each ⇒ Object
— Definición del Método Mixins Enumerable —.
-
#empty ⇒ Object
— Método que comprueba si la lista esta vacia —.
-
#extract_back ⇒ Object
— Método para extraer elementos desde el final de la lista —.
-
#extract_front ⇒ Object
— Método para extraer elementos desde el inicio de la lista —.
-
#initialize ⇒ C_LinkedList
constructor
A new instance of C_LinkedList.
-
#insert_first(value) ⇒ Object
— Método para insertar el primer elemento de la lista —.
-
#mostrar_fin_inicio ⇒ Object
— Metodo para mostrar la lista Fin a Principio —.
-
#mostrar_inicio_fin ⇒ Object
— Método para mostrar la lista Principio a Fin —.
-
#push_back(nodo) ⇒ Object
— Metodo para insertar un elemento a la lista por el final —.
-
#push_front(nodo) ⇒ Object
— Método para insertar un elemento a la lista por el inicio —.
Constructor Details
#initialize ⇒ C_LinkedList
Returns a new instance of C_LinkedList.
5 6 7 8 |
# File 'lib/menus/LinkedList.rb', line 5 def initialize() @a_inicio = nil @a_fin = nil end |
Instance Attribute Details
#a_fin ⇒ Object
Returns the value of attribute a_fin.
3 4 5 |
# File 'lib/menus/LinkedList.rb', line 3 def a_fin @a_fin end |
#a_inicio ⇒ Object
Returns the value of attribute a_inicio.
3 4 5 |
# File 'lib/menus/LinkedList.rb', line 3 def a_inicio @a_inicio end |
Instance Method Details
#each ⇒ Object
— Definición del Método Mixins Enumerable —
12 13 14 15 16 17 18 |
# File 'lib/menus/LinkedList.rb', line 12 def each nodo = @a_inicio while nodo != nil yield nodo.value nodo = nodo.next end end |
#empty ⇒ Object
— Método que comprueba si la lista esta vacia —
22 23 24 25 26 27 28 |
# File 'lib/menus/LinkedList.rb', line 22 def empty if ((@a_inicio == nil) && (a_fin == nil)) true else false end end |
#extract_back ⇒ Object
— Método para extraer elementos desde el final de la lista —
85 86 87 88 89 90 91 92 93 |
# File 'lib/menus/LinkedList.rb', line 85 def extract_back if (empty == true) puts "La lista en el metodo extract_back esta vacia" else aux = @a_fin @a_fin = @a_fin.previus aux end end |
#extract_front ⇒ Object
— Método para extraer elementos desde el inicio de la lista —
39 40 41 42 43 44 45 46 47 |
# File 'lib/menus/LinkedList.rb', line 39 def extract_front if (empty == true) puts "La lista en el metodo extract_front esta vacia" else aux = @a_inicio @a_inicio = @a_inicio.next aux end end |
#insert_first(value) ⇒ Object
— Método para insertar el primer elemento de la lista —
32 33 34 35 |
# File 'lib/menus/LinkedList.rb', line 32 def insert_first(value) @a_fin = value @a_inicio = value end |
#mostrar_fin_inicio ⇒ Object
— Metodo para mostrar la lista Fin a Principio —
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/menus/LinkedList.rb', line 113 def mostrar_fin_inicio if (empty == true) puts "--- La lista esta vacia ---" else puts puts "--- LA LISTA DEL FINAL AL PRINCIPIO ES, " puts aux = @a_fin puts @a_fin.value while aux.previus do puts "--------------" aux = aux.previus puts aux.value end end end |
#mostrar_inicio_fin ⇒ Object
— Método para mostrar la lista Principio a Fin —
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/menus/LinkedList.rb', line 66 def mostrar_inicio_fin if (empty == true) puts "--- La lista esta vacia ---" else puts puts "--- LA LISTA DEL PRINCIPIO AL FINAL ES, " puts aux = @a_inicio puts @a_inicio.value while aux.next do puts "--------------" aux = aux.next puts aux.value end end end |
#push_back(nodo) ⇒ Object
— Metodo para insertar un elemento a la lista por el final —
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/menus/LinkedList.rb', line 97 def push_back(nodo) nodo.each do |value| if (empty == true) puts "---- Metodo INSERTAR_FINAL, La lista esta vacia ----" insert_first(value) else aux = @a_fin @a_fin = value aux.next = @a_fin @a_fin.previus = aux end end end |
#push_front(nodo) ⇒ Object
— Método para insertar un elemento a la lista por el inicio —
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/menus/LinkedList.rb', line 51 def push_front(nodo) nodo.each do |value| if (empty == true) insert_first(value) else aux = @a_inicio @a_inicio = value aux.previus = @a_inicio @a_inicio.next = aux end end end |