Class: Lista

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLista

Returns a new instance of Lista.



11
12
13
14
15
16
# File 'lib/referencia/lista.rb', line 11

def initialize
    @head = Nodo.new(nil)
    @head = nil
    @tail = Nodo.new(nil)
    @tail = nil
end

Instance Attribute Details

#headObject

Returns the value of attribute head.



9
10
11
# File 'lib/referencia/lista.rb', line 9

def head
  @head
end

#next_nodeObject

Returns the value of attribute next_node.



9
10
11
# File 'lib/referencia/lista.rb', line 9

def next_node
  @next_node
end

#prev_nodeObject

Returns the value of attribute prev_node.



9
10
11
# File 'lib/referencia/lista.rb', line 9

def prev_node
  @prev_node
end

#tailObject

Returns the value of attribute tail.



9
10
11
# File 'lib/referencia/lista.rb', line 9

def tail
  @tail
end

#valueObject

Returns the value of attribute value.



9
10
11
# File 'lib/referencia/lista.rb', line 9

def value
  @value
end

Instance Method Details

#add_final(nodo) ⇒ Object



40
41
42
43
44
45
# File 'lib/referencia/lista.rb', line 40

def add_final(nodo)
    aux = Nodo.new(nodo, nil, nil)
    aux.prev_node = @tail
    @tail.next_node = aux
    @tail = aux
end

#add_muchos(nodo) ⇒ Object



55
56
57
58
59
# File 'lib/referencia/lista.rb', line 55

def add_muchos(nodo)
    nodo.each do |num| 
        self.add_principio(num)
    end
end

#add_principio(nodo) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/referencia/lista.rb', line 18

def add_principio(nodo)
    aux = Nodo.new(nodo, nil, nil)
    if (@head == nil && @tail == nil)
        @head = aux
        @tail = aux
    else
        aux.next_node = @head
        @head.prev_node = aux
        @head = aux
    end
end

#borrar_finalObject



35
36
37
38
# File 'lib/referencia/lista.rb', line 35

def borrar_final
    @tail = @tail.prev_node
    @tail.next_node = nil
end

#borrar_principioObject



30
31
32
33
# File 'lib/referencia/lista.rb', line 30

def borrar_principio
    @head = @head.next_node
    @head.prev_node = nil
end

#eachObject



47
48
49
50
51
52
53
# File 'lib/referencia/lista.rb', line 47

def each
    i = @head
    while (i != nil) 
        yield i.value
        i = i.next_node
    end
end