Class: Queue

Inherits:
Object
  • Object
show all
Defined in:
lib/data_structures/queue.rb

Instance Method Summary collapse

Constructor Details

#initializeQueue

Returns a new instance of Queue.



2
3
4
# File 'lib/data_structures/queue.rb', line 2

def initialize
  @store = Array.new
end

Instance Method Details

#<<(el) ⇒ Object



32
33
34
# File 'lib/data_structures/queue.rb', line 32

def <<(el)
  @store << el
end

#==(other_queue) ⇒ Object



18
19
20
21
# File 'lib/data_structures/queue.rb', line 18

def ==(other_queue)
  return false unless other_queue.is_a?(Queue)
  @store == other_queue.send(:store)
end

#dequeueObject



36
37
38
# File 'lib/data_structures/queue.rb', line 36

def dequeue
  @store.shift
end

#empty?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/data_structures/queue.rb', line 23

def empty?
  @store.empty?
end

#enqueue(el) ⇒ Object



27
28
29
30
# File 'lib/data_structures/queue.rb', line 27

def enqueue(el)
  @store.push(el)
  self
end

#include?(el) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/data_structures/queue.rb', line 48

def include?(el)
  @store.include?(el)
end

#inspectObject



14
15
16
# File 'lib/data_structures/queue.rb', line 14

def inspect
  @store
end

#lengthObject



44
45
46
# File 'lib/data_structures/queue.rb', line 44

def length
  @store.length
end

#peekObject



40
41
42
# File 'lib/data_structures/queue.rb', line 40

def peek
  @store.first
end

#to_aObject



6
7
8
# File 'lib/data_structures/queue.rb', line 6

def to_a
  Array.new(@store)
end

#to_sObject



10
11
12
# File 'lib/data_structures/queue.rb', line 10

def to_s
  @store
end