This repository has been archived on 2021-10-31. You can view files and clone it, but cannot push or open issues or pull requests.
sys_prog/collections/queue.py

21 lines
493 B
Python
Raw Normal View History

2019-09-01 12:52:45 +00:00
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