class Zadt::MinMaxStackQueue

Public Class Methods

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

Public Instance Methods

dequeue() click to toggle source
# File lib/zadt/AbstractDataTypes/StackQueue/MinMaxStackQueue.rb, line 21
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/MinMaxStackQueue.rb, line 63
def empty?
  @in.empty? && @out.empty?
end
enqueue(val) click to toggle source
# File lib/zadt/AbstractDataTypes/StackQueue/MinMaxStackQueue.rb, line 17
def enqueue(val)
  @in.push(val)
end
help() click to toggle source
# File lib/zadt/HelpModules/Functionality/StackQueue/MinMaxStackQueue.rb, line 7
def help
  MinMaxStackQueue.help
end
length() click to toggle source
# File lib/zadt/AbstractDataTypes/StackQueue/MinMaxStackQueue.rb, line 59
def length
  @in.length + @out.length
end
max() click to toggle source
# File lib/zadt/AbstractDataTypes/StackQueue/MinMaxStackQueue.rb, line 49
def max
  if @in.empty?
    @out.max
  elsif @out.empty?
    @in.max
  else
    [@in.max, @out.max].max
  end
end
min() click to toggle source
# File lib/zadt/AbstractDataTypes/StackQueue/MinMaxStackQueue.rb, line 39
def min
  if @in.empty?
    @out.min
  elsif @out.empty?
    @in.min
  else
    [@in.min, @out.min].min
  end
end
peek() click to toggle source
# File lib/zadt/AbstractDataTypes/StackQueue/MinMaxStackQueue.rb, line 30
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/MinMaxStackQueue.rb, line 13
def show
  @out.show.reverse + @in.show
end