Class: Queue
- Inherits:
-
Object
- Object
- Queue
- Defined in:
- lib/data_structures/queue.rb
Instance Method Summary collapse
- #<<(el) ⇒ Object
- #==(other_queue) ⇒ Object
- #dequeue ⇒ Object
- #empty? ⇒ Boolean
- #enqueue(el) ⇒ Object
- #include?(el) ⇒ Boolean
-
#initialize ⇒ Queue
constructor
A new instance of Queue.
- #inspect ⇒ Object
- #length ⇒ Object
- #peek ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Queue
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 |
#dequeue ⇒ Object
36 37 38 |
# File 'lib/data_structures/queue.rb', line 36 def dequeue @store.shift end |
#empty? ⇒ 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
48 49 50 |
# File 'lib/data_structures/queue.rb', line 48 def include?(el) @store.include?(el) end |
#inspect ⇒ Object
14 15 16 |
# File 'lib/data_structures/queue.rb', line 14 def inspect @store end |
#length ⇒ Object
44 45 46 |
# File 'lib/data_structures/queue.rb', line 44 def length @store.length end |
#peek ⇒ Object
40 41 42 |
# File 'lib/data_structures/queue.rb', line 40 def peek @store.first end |
#to_a ⇒ Object
6 7 8 |
# File 'lib/data_structures/queue.rb', line 6 def to_a Array.new(@store) end |
#to_s ⇒ Object
10 11 12 |
# File 'lib/data_structures/queue.rb', line 10 def to_s @store end |