Class: List
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
-
#initialize(head) ⇒ List
constructor
A new instance of List.
- #insert_head(nodo) ⇒ Object
- #insert_tail(nodo) ⇒ Object
- #print ⇒ Object
- #remove_head ⇒ Object
- #remove_tail ⇒ Object
Constructor Details
#initialize(head) ⇒ List
Returns a new instance of List.
21 22 23 24 25 26 27 28 |
# File 'lib/exam1/linkedlist.rb', line 21 def initialize(head) @head = head @tail = head end |
Instance Attribute Details
#head ⇒ Object
Returns the value of attribute head.
17 18 19 |
# File 'lib/exam1/linkedlist.rb', line 17 def head @head end |
#tail ⇒ Object
Returns the value of attribute tail.
17 18 19 |
# File 'lib/exam1/linkedlist.rb', line 17 def tail @tail end |
Instance Method Details
#each ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/exam1/linkedlist.rb', line 87 def each actual = @tail while actual != nil yield actual.value actual = actual.siguiente end end |
#insert_head(nodo) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/exam1/linkedlist.rb', line 30 def insert_head(nodo) aux = @head @head.siguiente = nodo @head = @head.siguiente @head.previo = aux end |
#insert_tail(nodo) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/exam1/linkedlist.rb', line 42 def insert_tail(nodo) aux = @tail @tail = nodo aux.previo = @tail @tail.siguiente = aux end |
#print ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/exam1/linkedlist.rb', line 63 def print actual = @tail while actual != nil "#{actual.value}" actual = actual.siguiente end end |
#remove_head ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/exam1/linkedlist.rb', line 51 def remove_head aux = @head @head = @head.previo return aux.value #puts @head.value end |
#remove_tail ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/exam1/linkedlist.rb', line 76 def remove_tail actual = @tail if @tail.siguiente != nil @tail = @tail.siguiente end return actual.value end |