Sha256: b502154aa043fdf1877a7ae74e85b0ed6f654f15d7ac666c8717718a8db0f9a0
Contents?: true
Size: 1.75 KB
Versions: 1
Compression:
Stored size: 1.75 KB
Contents
class List include Enumerable attr_accessor :top, :last Node = Struct.new(:value, :prev, :next) def initialize(top) if top === nil @top = nil @last = nil else @top = Node.new(top,nil,nil) @last = Node.new(top,nil,nil) end end def insertarMultiple(elementos) elementos.each do |elemento| insertar(elemento) end end def insertar(elemento) if empty @top = Node.new(elemento,nil, nil) @last = Node.new(elemento,nil, nil) else @top[:next] = elemento; nmenu = Node.new(elemento, @top, nil) @top = nmenu end end def mostrarUltimo if empty puts "Lista vacia. Empty!" else aux = @top; while aux[:prev] != nil aux = aux[:prev] end aux[:value] end end def extraer if empty puts "Lista vacia. Empty!" else extraer = @top[:value] aux_to = @top[:prev] if @top == @last @last = nil; end aux_to[:next] = nil @top = aux_to extraer end end def empty if @top == nil true else false end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
p11-0.0.0 | lib/dieta/Lista.rb |