Class: Lista
Instance Attribute Summary collapse
-
#head ⇒ Object
Returns the value of attribute head.
-
#lastnext ⇒ Object
Returns the value of attribute lastnext.
-
#puntero ⇒ Object
Returns the value of attribute puntero.
Instance Method Summary collapse
- #add(*args) ⇒ Object
- #add_s(value) ⇒ Object
- #each ⇒ Object
- #first ⇒ Object
-
#initialize ⇒ Lista
constructor
A new instance of Lista.
- #reverse ⇒ Object
- #reverse_each ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Lista
Returns a new instance of Lista.
6 7 8 9 |
# File 'lib/nodelist/list.rb', line 6 def initialize() @head = nil @lastnext = nil end |
Instance Attribute Details
#head ⇒ Object
Returns the value of attribute head.
5 6 7 |
# File 'lib/nodelist/list.rb', line 5 def head @head end |
#lastnext ⇒ Object
Returns the value of attribute lastnext.
5 6 7 |
# File 'lib/nodelist/list.rb', line 5 def lastnext @lastnext end |
#puntero ⇒ Object
Returns the value of attribute puntero.
5 6 7 |
# File 'lib/nodelist/list.rb', line 5 def puntero @puntero end |
Instance Method Details
#add(*args) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/nodelist/list.rb', line 39 def add(*args) args.each do |value| if @head == nil then @head = Node.new(value, nil, nil) @lastnext = @head else last = Node.new(value, nil, @lastnext) last.father = @lastnext @lastnext.next = last @lastnext = last end end end |
#add_s(value) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/nodelist/list.rb', line 28 def add_s(value) if @head == nil then @head = Node.new(value, nil, nil) @lastnext = @head else last = Node.new(value, nil, @lastnext) last.father = @lastnext @lastnext.next = last @lastnext = last end end |
#each ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/nodelist/list.rb', line 10 def each aux = @head while aux != nil yield aux.value aux = aux.next end end |
#first ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/nodelist/list.rb', line 52 def first if @head != nil then aux = @head.value @head = @head.next return aux else return -1 end end |
#reverse ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/nodelist/list.rb', line 21 def reverse list = Array.new @head.reverse{|x| list.push(x.value)} @head = nil @lastnext = nil list.each{|x| self.add(x)} end |
#reverse_each ⇒ Object
17 18 19 |
# File 'lib/nodelist/list.rb', line 17 def reverse_each @head.each {yield @lastnext.value; @lastnext=@lastnext.father} if @lastnext != nil end |
#to_a ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/nodelist/list.rb', line 64 def to_a a_value = Array.new pointer = @head while pointer.next != nil do a_value.push(pointer.value) pointer = pointer.next end a_value.push(pointer.value) a_value.to_s end |
#to_s ⇒ Object
61 62 63 |
# File 'lib/nodelist/list.rb', line 61 def to_s "#{@head}" end |