Class: Zadt::StackQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/zadt/AbstractDataTypes/MinMaxStackQueue/StackQueue.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStackQueue

Returns a new instance of StackQueue.



7
8
9
10
# File 'lib/zadt/AbstractDataTypes/MinMaxStackQueue/StackQueue.rb', line 7

def initialize
  @in = Stack.new
  @out = Stack.new
end

Class Method Details

.helpObject



12
13
14
15
16
17
18
19
# File 'lib/zadt/AbstractDataTypes/MinMaxStackQueue/StackQueue.rb', line 12

def self.help
  puts "Here are the functions for StackQueue:"
  puts "#show"
  puts "#enqueue(value)"
  puts "#dequeue"
  puts "#length"
  puts "#empty?"
end

.methodsObject



21
22
23
# File 'lib/zadt/AbstractDataTypes/MinMaxStackQueue/StackQueue.rb', line 21

def self.methods
  self.help
end

Instance Method Details

#dequeueObject



41
42
43
44
45
46
47
48
# File 'lib/zadt/AbstractDataTypes/MinMaxStackQueue/StackQueue.rb', line 41

def dequeue
  if @out.empty?
    @in.length.times do
      @out.push(@in.pop)
    end
  end
  @out.pop
end

#empty?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/zadt/AbstractDataTypes/MinMaxStackQueue/StackQueue.rb', line 54

def empty?
  @values.empty?
end

#enqueue(val) ⇒ Object



37
38
39
# File 'lib/zadt/AbstractDataTypes/MinMaxStackQueue/StackQueue.rb', line 37

def enqueue(val)
  @in.push(val)
end

#helpObject



25
26
27
# File 'lib/zadt/AbstractDataTypes/MinMaxStackQueue/StackQueue.rb', line 25

def help
  StackQueue.help
end

#lengthObject



50
51
52
# File 'lib/zadt/AbstractDataTypes/MinMaxStackQueue/StackQueue.rb', line 50

def length
  @in.length + @out.length
end

#methodsObject



29
30
31
# File 'lib/zadt/AbstractDataTypes/MinMaxStackQueue/StackQueue.rb', line 29

def methods
  help
end

#showObject



33
34
35
# File 'lib/zadt/AbstractDataTypes/MinMaxStackQueue/StackQueue.rb', line 33

def show
  @out.show.reverse + @in.show
end