Class: Algorithmable::DataStructs::Queue
- Inherits:
-
Object
- Object
- Algorithmable::DataStructs::Queue
show all
- Extended by:
- Forwardable
- Includes:
- Errors
- Defined in:
- lib/algorithmable/data_structs/queue.rb
Constant Summary
Constants included
from Errors
Errors::NoSuchElementError
Instance Method Summary
collapse
Constructor Details
#initialize(collection = []) ⇒ Queue
Returns a new instance of Queue.
9
10
11
|
# File 'lib/algorithmable/data_structs/queue.rb', line 9
def initialize(collection = [])
@imp = Deque.new collection
end
|
Instance Method Details
#dequeue ⇒ Object
23
24
25
|
# File 'lib/algorithmable/data_structs/queue.rb', line 23
def dequeue
@imp.pop_front
end
|
#enqueue(item) ⇒ Object
19
20
21
|
# File 'lib/algorithmable/data_structs/queue.rb', line 19
def enqueue(item)
@imp.push_back(item)
end
|
#peek ⇒ Object
13
14
15
16
17
|
# File 'lib/algorithmable/data_structs/queue.rb', line 13
def peek
peek_value = @imp.peek_front
fail NoSuchElementError unless peek_value
peek_value
end
|