-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue_class.py
More file actions
18 lines (17 loc) · 833 Bytes
/
queue_class.py
File metadata and controls
18 lines (17 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class queue:
def __init__(self, arr, max_size): #----------define the variable where the array is held and the max size of the queue
self.arr = arr
self.max_size = max_size
def isFull(self):
if len(self.arr) == self.max_size: #-------define a method to check if the queue is full
return True
else:
return False
def enqueue(self, item): #--------if the queue is full, append the new item and remove the first item
if self.isFull():
for i in range(1, len(self.arr)):
self.arr[i-1] = self.arr[i]
self.arr[-1] = item
else:
self.arr.append(item) #--------if it is not full then append the new item at the end
return self.arr