class Zadt::StackQueue

Public Class Methods

help() click to toggle source
# File lib/zadt/HelpModules/Functionality/StackQueue/StackQueue.rb, line 3
def self.help
  Zadt::ADT::show_stackqueue_help_message
end
new() click to toggle source
# File lib/zadt/AbstractDataTypes/StackQueue/StackQueue.rb, line 7
def initialize
  @in = Stack.new
  @out = Stack.new
end

Public Instance Methods

dequeue() click to toggle source
# File lib/zadt/AbstractDataTypes/StackQueue/StackQueue.rb, line 20
def dequeue
  if @out.empty?
    @in.length.times do
      @out.push(@in.pop)
    end
  end
  @out.pop
end
empty?() click to toggle source
# File lib/zadt/AbstractDataTypes/StackQueue/StackQueue.rb, line 42
def empty?
  @in.empty? && @out.empty?
end
enqueue(val) click to toggle source
# File lib/zadt/AbstractDataTypes/StackQueue/StackQueue.rb, line 16
def enqueue(val)
  @in.push(val)
end
help() click to toggle source
# File lib/zadt/HelpModules/Functionality/StackQueue/StackQueue.rb, line 7
def help
  StackQueue.help
end
length() click to toggle source
# File lib/zadt/AbstractDataTypes/StackQueue/StackQueue.rb, line 38
def length
  @in.length + @out.length
end
peek() click to toggle source
# File lib/zadt/AbstractDataTypes/StackQueue/StackQueue.rb, line 29
def peek
  if @out.empty?
    @in.length.times do
      @out.push(@in.pop)
    end
  end
  @out.peek
end
show() click to toggle source
# File lib/zadt/AbstractDataTypes/StackQueue/StackQueue.rb, line 12
def show
  @out.show.reverse + @in.show
end