class Lista
Attributes
head[R]
tail[R]
Public Class Methods
new()
click to toggle source
# File lib/alimento/lista.rb, line 8 def initialize() @head=@tail=nil end
Public Instance Methods
[](index)
click to toggle source
# File lib/alimento/lista.rb, line 98 def [] (index) i=0 aux=@head while i<index&&aux!=nil do i+=1 aux=aux.next_ end aux end
add_back(dato)
click to toggle source
# File lib/alimento/lista.rb, line 12 def add_back(dato) if dato.instance_of?Alimento node=Nodo.new(dato,nil,nil) @head=node if @head.nil? node.prev_=@tail unless @tail.nil? @tail.next_=node unless @tail.nil? @tail=node end if dato.instance_of?Array i=0 while i<dato.length do node=Nodo.new(dato[i],nil,nil) @head=node if @head.nil? node.prev_=@tail unless @tail.nil? @tail.next_=node unless @tail.nil? @tail=node i+=1 end end end
add_front(dato)
click to toggle source
# File lib/alimento/lista.rb, line 35 def add_front(dato) if dato.instance_of?Alimento node=Nodo.new(dato,nil,nil) @tail = node if @tail.nil? node.next_ = @head unless @head.nil? @head.prev_ = node unless @head.nil? @head = node end if dato.instance_of?Array i=0 while i<dato.length do @tail = node if @tail.nil? node.next_ = @head unless @head.nil? @head.prev_ = node unless @head.nil? @head = node i+=1 end end end
each() { |dato| ... }
click to toggle source
# File lib/alimento/lista.rb, line 108 def each aux=@head while aux!=nil do yield aux.dato aux=aux.next_ end end
mostrar()
click to toggle source
# File lib/alimento/lista.rb, line 88 def mostrar str= "" aux=@head while aux!=nil do str+="\t"+aux.dato.to_s+"\n" aux=aux.next_ end str end
pop_back()
click to toggle source
# File lib/alimento/lista.rb, line 56 def pop_back if (@tail==@head)&&(@tail==nil) return nil elsif @tail==@head aux=@tail.dup @tail=@head=nil return aux else aux=@tail.dup @tail=@tail.prev_ @tail.next_=nil aux.prev_=nil return aux end end
pop_front()
click to toggle source
# File lib/alimento/lista.rb, line 72 def pop_front if (@tail==@head)&&(@tail==nil) return nil elsif @tail==@head aux=@head.dup @head=@tail=nil return aux else aux=@head.dup @head=@head.next_ @head.prev_=nil aux.next_=nil return aux end end