Class: List
- Inherits:
-
Object
- Object
- List
- Defined in:
- lib/practica6/lista.rb
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
- #empty? ⇒ Boolean
- #ex_1er_elemento ⇒ Object
- #extract_tail ⇒ Object
-
#initialize ⇒ List
constructor
A new instance of List.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ List
Returns a new instance of List.
6 7 8 9 |
# File 'lib/practica6/lista.rb', line 6 def initialize @head = @tail = nil @contador=0 end |
Instance Attribute Details
#head ⇒ Object
Returns the value of attribute head.
4 5 6 |
# File 'lib/practica6/lista.rb', line 4 def head @head end |
#prev ⇒ Object
Returns the value of attribute prev.
4 5 6 |
# File 'lib/practica6/lista.rb', line 4 def prev @prev end |
#tail ⇒ Object
Returns the value of attribute tail.
4 5 6 |
# File 'lib/practica6/lista.rb', line 4 def tail @tail end |
Instance Method Details
#add(value) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/practica6/lista.rb', line 11 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 end |
#empty? ⇒ Boolean
34 35 36 37 38 39 40 41 |
# File 'lib/practica6/lista.rb', line 34 def empty? if @head.nil? return true else return false end end |
#ex_1er_elemento ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/practica6/lista.rb', line 23 def ex_1er_elemento() if @head.nil? return false end @aux3=head @head = @head.next @aux3.next=nil end |
#extract_tail ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/practica6/lista.rb', line 43 def extract_tail() aux="" if(@tail == nil) return false else aux = @tail.value @tail = @tail.prev return aux end end |
#to_s ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/practica6/lista.rb', line 56 def to_s @aux=head aux2="" while @aux != nil do aux2 += "#{@aux.value.to_s}" @aux=@aux.next end "#{aux2}" end |