Nodo = Struct.new(:value, :next, :prev) class Lista include Enumerable attr_accessor :head, :cola, :nodo_actual def initialize(head,cola) @head = head @cola = cola end def insert(x) node = Nodo.new(x,nil,nil) if @head==nil && @cola==nil node.prev = @cola node.next = @head @nodo_actual = node @head = node @cola = node else node.prev = @head node.next = nil @nodo_actual = node @head.next = node @head = node end end def insert_multiple(nodos) nodos.each do |nd| insert(nd) end end #eliminar el nodo y cambiar los valores al nodo anterior def extract() @cola=@cola.next end def extract_final() @head = @head.prev end def to_s @head.to_s end def each while @head != @cola yield @head.value @head=@head.prev end if @head == @cola if @head == nil nil else yield @cola.value end end end end