Class: DLL

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(val) ⇒ DLL

Returns a new instance of DLL.



9
10
11
12
# File 'lib/etiqueta/DLL.rb', line 9

def initialize(val)
   @head = Node.new(val,nil,nil)
   @tail = @head
end

Instance Attribute Details

#headObject (readonly)

Returns the value of attribute head.



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

def head
  @head
end

#tailObject (readonly)

Returns the value of attribute tail.



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

def tail
  @tail
end

Instance Method Details

#clasificacionObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/etiqueta/DLL.rb', line 50

def clasificacion
    puntero = @head
    puntero2 = ""
    cart = Array.new
    while (puntero != nil) do
        if (puntero.value.getSal <= 4)
            puntero2 = "Bajo en Sal"
        end
        if (puntero.value.getSal > 4 && puntero.value.getSal <= 20)
            puntero2 = "Medio en Sal"
        end
        if(puntero.value.getSal > 20)
            puntero2 = "Alto en Sal"
        end
        cart.push(puntero.value.getNombre + "," + " " + puntero2)
        puntero = puntero.next_
    end
   cart.sort
end

#clasificacionImcObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/etiqueta/DLL.rb', line 70

def clasificacionImc
    aux = @head
    cart = Array.new
    while(aux != nil) do
    if(aux.value.calculateimc < 18.5)
        aux.value.valor = 'delgado'
    end
    if(aux.value.calculateimc >= 18.5 && aux.value.calculateimc < 24.9)
        aux.value.valor = 'medio'
    end
    if(aux.value.calculateimc >= 24.9)
        aux.value.valor = 'obeso'
    end
    
    cart.push(aux.value.nombre + "," + " " + aux.value.valor)
    aux = aux.next_
end
cart.sort
end

#each(&block) ⇒ Object



90
91
92
93
94
95
96
# File 'lib/etiqueta/DLL.rb', line 90

def each(&block)
    aux = @head
    while(aux != nil) do
        yield aux.value
        aux = aux.next_
    end
end

#extract_headObject



26
27
28
29
30
31
# File 'lib/etiqueta/DLL.rb', line 26

def extract_head
   puntero = @head.value
   @head = @head.next_
   @head.prev = nil
   return puntero
end

#extract_tailObject



33
34
35
36
37
38
# File 'lib/etiqueta/DLL.rb', line 33

def extract_tail
   puntero = @tail.value
   @tail = @tail.prev
   @tail.next_ = nil
   return puntero
end

#insert_head(val) ⇒ Object



20
21
22
23
24
# File 'lib/etiqueta/DLL.rb', line 20

def insert_head(val)
   aux = Node.new(val,@head,nil)
   @head.prev = aux
   @head = aux
end

#insert_tail(val) ⇒ Object



14
15
16
17
18
# File 'lib/etiqueta/DLL.rb', line 14

def insert_tail(val)
   aux = Node.new(val,nil,@tail)
   @tail.next_ = aux
   @tail = aux
end

#to_sObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/etiqueta/DLL.rb', line 39

def to_s
    string = "("
    puntero = @head
    while (puntero != nil) do
        string += "#{puntero.value.getSal} gr,"
        puntero = puntero.next_
    end
    string += ")"
    return string
end