Class: Linked
Instance Attribute Summary collapse
-
#head ⇒ Object
Returns the value of attribute head.
-
#prev ⇒ Object
Returns the value of attribute prev.
-
#tail ⇒ Object
Returns the value of attribute tail.
Instance Method Summary collapse
- #add(value) ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
- #ex_1er_elemento ⇒ Object
- #extract_tail ⇒ Object
-
#initialize ⇒ Linked
constructor
A new instance of Linked.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Linked
Returns a new instance of Linked.
9 10 11 12 |
# File 'lib/prct6/linked.rb', line 9 def initialize @head = @tail = nil @contador=0 end |
Instance Attribute Details
#head ⇒ Object
Returns the value of attribute head.
7 8 9 |
# File 'lib/prct6/linked.rb', line 7 def head @head end |
#prev ⇒ Object
Returns the value of attribute prev.
7 8 9 |
# File 'lib/prct6/linked.rb', line 7 def prev @prev end |
#tail ⇒ Object
Returns the value of attribute tail.
7 8 9 |
# File 'lib/prct6/linked.rb', line 7 def tail @tail end |
Instance Method Details
#add(value) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/prct6/linked.rb', line 14 def add(value) node = Node.new(value) @head = node if @head.nil? if(@tail!=nil) @tail.next = node node.prev = @tail @contador=@contador+1 end @tail = node #@contador=@contador+1 end |
#each ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/prct6/linked.rb', line 79 def each nodo = head while(nodo != nil) yield nodo.value[1][3] nodo = nodo.next end end |
#empty? ⇒ Boolean
56 57 58 59 60 61 62 63 |
# File 'lib/prct6/linked.rb', line 56 def empty? if @head.nil? return true else return false end end |
#ex_1er_elemento ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/prct6/linked.rb', line 45 def ex_1er_elemento() if @head.nil? return false end @aux3=head @head = @head.next @aux3.next=nil end |
#extract_tail ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/prct6/linked.rb', line 65 def extract_tail() aux="" if(@tail == nil) return false else aux = @tail.value @tail = @tail.prev return aux end end |
#to_s ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/prct6/linked.rb', line 30 def to_s @aux=head aux2="" while @aux != nil do aux2 += "#{@aux.value.to_s}" @aux=@aux.next end "#{aux2}" end |