Class: List
Overview
Clase List
Representa las funcionalidades de una Lista Doblemente Enlazada
Instance Attribute Summary collapse
-
#head ⇒ Object
readonly
Returns the value of attribute head.
-
#tail ⇒ Object
readonly
Returns the value of attribute tail.
Instance Method Summary collapse
-
#each ⇒ Object
Método mixin del módulo Enumerable para poder enumerar.
-
#empty ⇒ Object
El método empty indica que la lista está vacía.
-
#extract ⇒ Object
Se extraen elementos de la lista.
-
#initialize ⇒ List
constructor
Se inicializa la lista con un head y un tail.
-
#insert(value) ⇒ Type
Se introducen elementos en la lista.
-
#sort_imc(lista) ⇒ Type
Clasificación de pacientes según su IM.
-
#to_s ⇒ String
Se imprime la lista por pantalla.
Constructor Details
#initialize ⇒ List
Se inicializa la lista con un head y un tail
14 15 16 17 |
# File 'lib/nutritag/list.rb', line 14 def initialize @head=nil @tail=nil end |
Instance Attribute Details
#head ⇒ Object (readonly)
Returns the value of attribute head.
9 10 11 |
# File 'lib/nutritag/list.rb', line 9 def head @head end |
#tail ⇒ Object (readonly)
Returns the value of attribute tail.
9 10 11 |
# File 'lib/nutritag/list.rb', line 9 def tail @tail end |
Instance Method Details
#each ⇒ Object
Método mixin del módulo Enumerable para poder enumerar
71 72 73 74 75 76 77 |
# File 'lib/nutritag/list.rb', line 71 def each aux = @head while (aux != nil) yield aux.value aux = aux.next end end |
#empty ⇒ Object
El método empty indica que la lista está vacía
20 21 22 23 |
# File 'lib/nutritag/list.rb', line 20 def empty @head==nil @tail==nil end |
#extract ⇒ Object
Se extraen elementos de la lista
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/nutritag/list.rb', line 45 def extract if (@head==nil&&@tail==nil) return nil else aux = @head @head.next = @head @head.prev = nil unless @head.nil? aux.next=nil aux end end |
#insert(value) ⇒ Type
Se introducen elementos en la lista
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/nutritag/list.rb', line 29 def insert(value) node = Node.new(value, nil, nil) if (@head==nil&&@tail==nil) @head=node @tail=node else @tail.next=node #node.prev=@tail @tail=node end end |
#sort_imc(lista) ⇒ Type
Clasificación de pacientes según su IM
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/nutritag/list.rb', line 83 def sort_imc(lista) obesidad = List.new() normalidad = List.new() node = lista.head while !(node.nil?) if node.value.imc >= 30 obesidad.insert(node.value) else normalidad.insert(node.value) end node = node.next end puts "Pacientes con Obesidad" obesidad.to_s puts "Pacientes con Normalidad" normalidad.to_s end |
#to_s ⇒ String
Se imprime la lista por pantalla
61 62 63 64 65 66 67 68 69 |
# File 'lib/nutritag/list.rb', line 61 def to_s n=@head puts "{" while (n!=nil) "#{n.value.to_s}" n=n.next end " }" end |