Class: Lista

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLista

Returns a new instance of Lista.



6
7
8
9
# File 'lib/gema/lista.rb', line 6

def initialize
        @head=nil
        @tail=nil
end

Instance Attribute Details

#headObject (readonly)

Returns the value of attribute head.



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

def head
  @head
end

#tailObject (readonly)

Returns the value of attribute tail.



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

def tail
  @tail
end

Instance Method Details

#eachObject



36
37
38
39
40
41
42
# File 'lib/gema/lista.rb', line 36

def each 
  		it = @head
  		while it != nil 
       		yield it.value
       		it=it.next
  		end
end

#empty?Boolean

Returns:

  • (Boolean)


10
11
12
13
# File 'lib/gema/lista.rb', line 10

def empty?
        @head==nil
        @head==nil
end

#get_headObject



25
26
27
28
29
# File 'lib/gema/lista.rb', line 25

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

#get_tailObject



31
32
33
34
35
# File 'lib/gema/lista.rb', line 31

def get_tail
    	aux = @tail
   		@tail = @tail.prev
  	 	aux
end

#insert(value) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gema/lista.rb', line 14

def insert(value)
        nodo = Node.new(value,nil,nil)
        if empty?
                @head=nodo
                @tail=nodo
        else
                @tail.next=nodo
                nodo.prev=@tail
                @tail = nodo 
        end 
end