Class: LinkedList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/practica7/practica7.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLinkedList

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

#headObject

Returns the value of attribute head.



5
6
7
# File 'lib/practica7/practica7.rb', line 5

def head
  @head
end

#tailObject

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

#eachObject

: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

#popObject



17
18
19
20
21
# File 'lib/practica7/practica7.rb', line 17

def pop
  		aux=@head
  		@head=@head.next
  		aux
end

#sizeObject



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