-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmyqueue.py
37 lines (30 loc) · 988 Bytes
/
myqueue.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class Queue:
'''
A basic queue implementation, which is thread safe as list is threadsafe but not safe to random operations done by user
It assumes a judicial usage by the user
Purposefully made for this assignment only, should not be used for general purpose
To extend to general purpose, will need to implement some exceptions and handle corner cases
'''
def __init__(self, max_size):
self.max_size = max_size
self.list = list()
def put(self, element):
self.list.append(element)
def get(self):
temp = self.top()
self.list.pop(0)
return temp
def empty(self):
if(len(self.list) == 0):
return True
return False
def full(self):
if(len(self.list) == self.max_size):
return True
return False
def top(self):
return self.list[0]
def clear(self):
self.list.clear()
def size(self) :
return len(self.list)