Skip to content

Commit 12e7397

Browse files
committed
Added initialize and enqueue methods
1 parent ece0376 commit 12e7397

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

lib/queue.rb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
11
class Queue
22

33
def initialize
4-
# @store = ...
5-
raise NotImplementedError, "Not yet implemented"
4+
@store = Array.new(10)
5+
@front = -1
6+
@back = -1
67
end
78

89
def enqueue(element)
9-
raise NotImplementedError, "Not yet implemented"
10+
#Check if queue is empty
11+
if @front == -1 && @back == -1
12+
@front = 0
13+
@back = 1
14+
end
15+
#Check if queue is full
16+
if @front == @back
17+
#Decide what to do if circular buffer is full
18+
end
19+
20+
@store(@back) = element
21+
@back += 1
22+
23+
#Make it wrap around when it reaches the end
24+
@back = (@back + 1) % @store.length
1025
end
1126

1227
def dequeue

0 commit comments

Comments
 (0)