Class: Lista
Instance Attribute Summary collapse
-
#cabeza ⇒ Object
readonly
Returns the value of attribute cabeza.
-
#cola ⇒ Object
readonly
Returns the value of attribute cola.
Instance Method Summary collapse
- #each {|aux.value| ... } ⇒ Object
-
#initialize ⇒ Lista
constructor
A new instance of Lista.
- #pop_first ⇒ Object
- #pop_last ⇒ Object
- #push(other) ⇒ Object
Constructor Details
#initialize ⇒ Lista
Returns a new instance of Lista
10 11 12 |
# File 'lib/lista.rb', line 10 def initialize() @cabeza,@cola = nil end |
Instance Attribute Details
#cabeza ⇒ Object (readonly)
Returns the value of attribute cabeza
8 9 10 |
# File 'lib/lista.rb', line 8 def cabeza @cabeza end |
#cola ⇒ Object (readonly)
Returns the value of attribute cola
8 9 10 |
# File 'lib/lista.rb', line 8 def cola @cola end |
Instance Method Details
#each {|aux.value| ... } ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/lista.rb', line 14 def each aux = @cabeza while aux != @cola do yield aux.value aux = aux.next end yield aux.value end |
#pop_first ⇒ Object
40 41 42 |
# File 'lib/lista.rb', line 40 def pop_first() @cabeza = @cabeza.next end |
#pop_last ⇒ Object
44 45 46 |
# File 'lib/lista.rb', line 44 def pop_last() @cola = @cola.prev end |
#push(other) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/lista.rb', line 23 def push(other) if @cabeza == nil @cabeza = other other.next = @cabeza other.prev = @cabeza @cola = other end if @cabeza != nil other.next = @cabeza other.prev = @cola @cola.next = other @cabeza.prev = other @cola = other end end |