Class: Lista
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 ⇒ Object
- #empty? ⇒ Boolean
- #get_head ⇒ Object
- #get_tail ⇒ Object
-
#initialize ⇒ Lista
constructor
A new instance of Lista.
- #insert(value) ⇒ Object
Constructor Details
#initialize ⇒ Lista
Returns a new instance of Lista.
6 7 8 9 |
# File 'lib/gema/lista.rb', line 6 def initialize @head=nil @tail=nil end |
Instance Attribute Details
#head ⇒ Object (readonly)
Returns the value of attribute head.
5 6 7 |
# File 'lib/gema/lista.rb', line 5 def head @head end |
#tail ⇒ Object (readonly)
Returns the value of attribute tail.
5 6 7 |
# File 'lib/gema/lista.rb', line 5 def tail @tail end |
Instance Method Details
#each ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/gema/lista.rb', line 36 def each it = @head while it != nil yield it.value it=it.next end end |
#empty? ⇒ Boolean
10 11 12 13 |
# File 'lib/gema/lista.rb', line 10 def empty? @head==nil @head==nil end |
#get_head ⇒ Object
25 26 27 28 29 |
# File 'lib/gema/lista.rb', line 25 def get_head aux = @head @head = @head.next aux end |
#get_tail ⇒ Object
31 32 33 34 35 |
# File 'lib/gema/lista.rb', line 31 def get_tail aux = @tail @tail = @tail.prev aux end |
#insert(value) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/gema/lista.rb', line 14 def insert(value) nodo = Node.new(value,nil,nil) if empty? @head=nodo @tail=nodo else @tail.next=nodo nodo.prev=@tail @tail = nodo end end |