forked from Data-Structures-4022-NIT/Queue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PriorityQueue.py
39 lines (33 loc) · 982 Bytes
/
PriorityQueue.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
38
39
class data:
def __init__(self , priority , item):
self.priority=priority
self.item=item
class PriorityQueue:
def __init__(self):
self.pQueue=[]
self.rear=0
self.front=0
def enqueue(self, item, priority):
if(self.isEmpty):
item=data(priority , item)
self.rear= self.rear+1
self.queue[rear] = item
else:
self.item=data(priority , item)
for i in range(0 , len(pQueue)):
if(pQueue[i].priority<= item.priority):
self.queue.insert(i ,item)
self.rear+=1
def dequeue(self):
if(self.isEmpty):
return "UnderFlow"
else:
return self.pQueue.pop()
self.front+=1
def isEmpty(self):
if(self.rear==self.front):
return True
else:
return False
def SizeOfQueue(self):
return self.rear-self.front