Class: LinkedList
- Inherits:
-
Object
- Object
- LinkedList
- Includes:
- Enumerable
- Defined in:
- lib/practica7/practica7.rb
Instance Attribute Summary collapse
-
#head ⇒ Object
Returns the value of attribute head.
-
#tail ⇒ Object
Returns the value of attribute tail.
Instance Method Summary collapse
- #add(value) ⇒ Object
-
#each ⇒ Object
:nodoc:.
-
#initialize ⇒ LinkedList
constructor
A new instance of LinkedList.
- #pop ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize ⇒ LinkedList
Returns a new instance of LinkedList.
7 8 9 |
# File 'lib/practica7/practica7.rb', line 7 def initialize @head = @tail = nil end |
Instance Attribute Details
#head ⇒ Object
Returns the value of attribute head.
5 6 7 |
# File 'lib/practica7/practica7.rb', line 5 def head @head end |
#tail ⇒ Object
Returns the value of attribute tail.
5 6 7 |
# File 'lib/practica7/practica7.rb', line 5 def tail @tail end |
Instance Method Details
#add(value) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/practica7/practica7.rb', line 10 def add(value) node = Node.new(value) @head = node if @head.nil? @tail.next = node unless @tail.nil? node.prev = @tail unless @tail.nil? @tail = node end |
#each ⇒ Object
:nodoc:
31 32 33 34 35 36 37 |
# File 'lib/practica7/practica7.rb', line 31 def each #:nodoc: aux=@head while aux!=nil do yield aux.value aux=aux.next end end |
#pop ⇒ Object
17 18 19 20 21 |
# File 'lib/practica7/practica7.rb', line 17 def pop aux=@head @head=@head.next aux end |
#size ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/practica7/practica7.rb', line 22 def size tam =0 aux=@head while aux!=nil do tam = tam + 1 aux=aux.next end tam end |