class BiblioRefs::List
Attributes
head[RW]
tail[RW]
Public Class Methods
new(*nodo)
click to toggle source
Constructor de la clase List
# File lib/biblio_refs/list.rb, line 11 def initialize(*nodo) @tail = @head = Nodo.new(nodo[0]) if nodo.size > 1 nodo.shift push(*nodo) end end
Public Instance Methods
each() { |aux| ... }
click to toggle source
Método que recorre todos los valores de los nodos de la lista Necesario para hacer la clase List enumerable, haciendo 'yield' a todos los valores
# File lib/biblio_refs/list.rb, line 21 def each aux = @head while aux[:next] yield aux[:value] aux = aux[:next] end yield aux[:value] end
pop()
click to toggle source
Método que devuelve y extrae el valor del primer nodo de la lista
# File lib/biblio_refs/list.rb, line 31 def pop nodo = @head @head = @head[:next] nodo[:value] end
push(*nodo)
click to toggle source
Método que inserta uno o varios nodos al final de la lista
# File lib/biblio_refs/list.rb, line 38 def push(*nodo) aux = @head nodo.each do |n| while aux[:next] do aux = aux[:next] end @tail = aux[:next] = Nodo.new(n, nil, aux) end end
to_s()
click to toggle source
Método que devuelve una cadena de carácteres formateada de los objetos de la clase List
# File lib/biblio_refs/list.rb, line 49 def to_s aux = @head string = "Lista: " while aux[:next] do string += "#{aux[:value]}" + " -> " aux = aux[:next] end string += "#{aux[:value]}" end