Class: Exam::List
- Inherits:
-
Object
- Object
- Exam::List
- Defined in:
- lib/exam/list.rb
Overview
create a List
Instance Attribute Summary collapse
-
#head ⇒ Object
Returns the value of attribute head.
Instance Method Summary collapse
-
#initialize(v) ⇒ List
constructor
A new instance of List.
- #popHead ⇒ Object
- #push(v) ⇒ Object
- #to_s ⇒ Object
Constructor Details
Instance Attribute Details
#head ⇒ Object
Returns the value of attribute head.
7 8 9 |
# File 'lib/exam/list.rb', line 7 def head @head end |
Instance Method Details
#popHead ⇒ Object
19 20 21 22 23 |
# File 'lib/exam/list.rb', line 19 def popHead nodo = @head @head=@head[:next] return nodo[:value] end |
#push(v) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/exam/list.rb', line 25 def push(v) aux = @head if v.kind_of?(Array) for i in 0..v.size-1 a=v[i] while aux[:next]!=nil do aux=aux[:next] end nuevo_nodo=Node.new(a, nil) aux[:next]=nuevo_nodo end else while aux[:next] do aux=aux[:next] end nuevo_nodo=Node.new(v, nil) aux[:next]=nuevo_nodo end end |
#to_s ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/exam/list.rb', line 45 def to_s aux=@head s="Lista: " while aux[:next] do s = s + "#{aux[:value]}" + " -> " aux=aux[:next] end s = s + "#{aux[:value]}" #puts "#{s}" end |