Class: Lista
Overview
Representación de una lista doblemente enlazada de nodos
Instance Attribute Summary collapse
-
#head ⇒ Object
readonly
Returns the value of attribute head.
-
#tail ⇒ Object
readonly
Returns the value of attribute tail.
Instance Method Summary collapse
-
#each ⇒ Node
Método para la enumeración de los nodos de la lista.
-
#pop_head ⇒ any?
Extracción del primer nodo de la lista.
-
#pop_tail ⇒ any?
Extracción del último nodo de la lista.
-
#push(x) ⇒ Node
Inserción por la cola de la lista de varios nodos.
-
#push_head(x) ⇒ Node
Inserción por la cabeza de la lista.
-
#push_tail(x) ⇒ Node
Inserción por la cola de la lista.
Instance Attribute Details
#head ⇒ Object (readonly)
Returns the value of attribute head.
9 10 11 |
# File 'lib/pr06/lista_d.rb', line 9 def head @head end |
#tail ⇒ Object (readonly)
Returns the value of attribute tail.
9 10 11 |
# File 'lib/pr06/lista_d.rb', line 9 def tail @tail end |
Instance Method Details
#each ⇒ Node
Método para la enumeración de los nodos de la lista
94 95 96 97 98 99 100 |
# File 'lib/pr06/lista_d.rb', line 94 def each x = @head while(x != nil) yield x.value x = x.next end end |
#pop_head ⇒ any?
Extracción del primer nodo de la lista
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/pr06/lista_d.rb', line 56 def pop_head() if(@head == nil) return nil end x = @head @head = @head.next if(@head == nil) @tail = nil else @head.prev = nil x.next = nil end x.value end |
#pop_tail ⇒ any?
Extracción del último nodo de la lista
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/pr06/lista_d.rb', line 75 def pop_tail() if(@tail == nil) return nil end x = @tail @tail = @tail.prev if(@tail == nil) @head = nil else @tail.next = nil x.prev = nil end x.value end |
#push(x) ⇒ Node
Inserción por la cola de la lista de varios nodos
47 48 49 50 51 |
# File 'lib/pr06/lista_d.rb', line 47 def push(x) x.each{ |i| push_tail(i) } end |