Class: Dll
Instance Attribute Summary collapse
-
#head ⇒ Object
Returns the value of attribute head.
-
#tail ⇒ Object
Returns the value of attribute tail.
Instance Method Summary collapse
- #each ⇒ Object
- #empty? ⇒ Boolean
- #get_head ⇒ Object
- #get_tail ⇒ Object
-
#initialize ⇒ Dll
constructor
A new instance of Dll.
- #insert_head(value) ⇒ Object
- #insert_tail(value) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Dll
Returns a new instance of Dll.
7 8 9 10 |
# File 'lib/tdd/dll_etiqueta.rb', line 7 def initialize @head = nil @tail = nil end |
Instance Attribute Details
#head ⇒ Object
Returns the value of attribute head.
5 6 7 |
# File 'lib/tdd/dll_etiqueta.rb', line 5 def head @head end |
#tail ⇒ Object
Returns the value of attribute tail.
5 6 7 |
# File 'lib/tdd/dll_etiqueta.rb', line 5 def tail @tail end |
Instance Method Details
#each ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/tdd/dll_etiqueta.rb', line 67 def each it = @head while it !=nil yield it.value it=it.next end end |
#empty? ⇒ Boolean
53 54 55 56 |
# File 'lib/tdd/dll_etiqueta.rb', line 53 def empty? @head == nil @tail == nil end |
#get_head ⇒ Object
41 42 43 44 45 |
# File 'lib/tdd/dll_etiqueta.rb', line 41 def get_head dummy = @head @head = @head.next dummy end |
#get_tail ⇒ Object
47 48 49 50 51 |
# File 'lib/tdd/dll_etiqueta.rb', line 47 def get_tail dummy = @tail @tail = @tail.prev dummy end |
#insert_head(value) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/tdd/dll_etiqueta.rb', line 12 def insert_head(value) nodo = Node.new(value,nil,nil) if(@head == nil) @head = nodo @tail = nodo else @head.prev = nodo nodo.next = @head @head = nodo end end |
#insert_tail(value) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/tdd/dll_etiqueta.rb', line 27 def insert_tail(value) nodo = Node.new(value,nil,nil) if(@tail ==nil) @tail=nodo @head=nodo else @tail.next=nodo nodo.prev=@tail @tail=nodo end end |
#to_s ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/tdd/dll_etiqueta.rb', line 59 def to_s it = @head while it!=nil puts it.value.to_s it=it.next end end |