class Exam::DList
create a DList
Attributes
head[RW]
tail[RW]
Public Class Methods
new(v)
click to toggle source
# File lib/exam/d_list.rb, line 19 def initialize(v) if v.kind_of?(Array) @head = Node.new(v[0],nil, nil) v.shift pushHead(v) else @head = Node.new(v, nil, nil) end end
Public Instance Methods
each() { |aux| ... }
click to toggle source
# File lib/exam/d_list.rb, line 9 def each aux=@head while aux[:next] yield aux[:value] aux=aux[:next] end yield aux[:value] end
popHead()
click to toggle source
# File lib/exam/d_list.rb, line 29 def popHead nodo = @head if nodo @head=@head[:next] if @head @head[:prev]=nil end return nodo[:value] end end
popTail()
click to toggle source
# File lib/exam/d_list.rb, line 40 def popTail nodo = @head if nodo while nodo[:next] do nodo=nodo[:next] end aux=nodo[:prev] aux[:next]=nil nodo[:prev]=nil return nodo[:value] end end
pushHead(v)
click to toggle source
# File lib/exam/d_list.rb, line 53 def pushHead(v) if v.kind_of?(Array) for i in 0..v.size-1 aux = @head nodo=Node.new(v[i], aux, nil) @head=nodo aux[:prev]=@head end else aux = @head nodo=Node.new(v, aux, nil) @head=nodo aux[:prev]=@head end end
pushTail(v)
click to toggle source
# File lib/exam/d_list.rb, line 69 def pushTail(v) aux = @head if v.kind_of?(Array) for i in 0..v.size-1 while aux[:next]!=nil do aux=aux[:next] end nuevo_nodo=Node.new(v[i], nil, aux) aux[:next]=nuevo_nodo end else while aux[:next] do aux=aux[:next] end nuevo_nodo=Node.new(v, nil, aux) aux[:next]=nuevo_nodo end end
size()
click to toggle source
# File lib/exam/d_list.rb, line 89 def size aux=@head n=0 while aux[:next] do n=n+1 aux=aux[:next] end n=n+1 end
to_is()
click to toggle source
# File lib/exam/d_list.rb, line 110 def to_is aux=@head s="" while aux[:next] do aux=aux[:next] end while aux[:prev] do s = s + "#{aux[:value]} " aux=aux[:prev] end s = s + "#{aux[:value]}" #puts "#{s}" end
to_s()
click to toggle source
# File lib/exam/d_list.rb, line 99 def to_s aux=@head s="" while aux[:next] do s = s + "#{aux[:value]} " aux=aux[:next] end s = s + "#{aux[:value]}" #puts "#{s}" end