21 lines
493 B
Python
21 lines
493 B
Python
|
class Queue:
|
||
|
def __init__(self, length):
|
||
|
self.length = length
|
||
|
self.arr = [None]*length
|
||
|
self.start = 0
|
||
|
self.size = 0
|
||
|
|
||
|
def enqueue(Q, x):
|
||
|
if Q.size == Q.length:
|
||
|
return "You broke it, congratulations!"
|
||
|
Q.arr[Q.start + Q.size] = x
|
||
|
Q.size = Q.size + 1
|
||
|
|
||
|
def dequeue(Q):
|
||
|
if Q.size == 0:
|
||
|
return "You broke it, congratulations!"
|
||
|
temp = Q.arr[Q.start]
|
||
|
Q.start = (Q.start + 1) % Q.length
|
||
|
Q.size = Q.size - 1
|
||
|
return temp
|