-
Notifications
You must be signed in to change notification settings - Fork 0
/
complaint.py
67 lines (57 loc) · 1.72 KB
/
complaint.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from ctypes import py_object
class priority_queue_node:
def __init__(self,item=None,pr=None):
self._item=item
self._priority=pr
self._next=None
class linked_priority_queue:
def __init__(self):
self._front=None
def isEmpty(self):
return self._front==None
def queue(self,value,pr):
if self.isEmpty():
self._front=priority_queue_node(value,pr)
return 1
else:
if self._front._priority < pr:
newNode=priority_queue_node(value,pr)
newNode._next=self._front
self._front=newNode
return 1
else:
temp=self._front
while temp._next:
if pr >= temp._next._priority:
break
temp = temp._next
newNode=priority_queue_node(value,pr)
newNode._next = temp._next
temp._next = newNode
return 1
def dequeue(self):
if self.isEmpty():
return
self._front=self._front._next
return 1
def peek(self):
if self.isEmpty():
return
else:
return self._front._item
def traverse(self):
if self.isEmpty():
return "Queue is Empty"
else:
temp=self._front
while temp:
print(temp._item, end=' ')
temp=temp._next
def __str__(self):
res='['
temp=self._front
while temp:
res+=str(temp._item)+','
temp=temp._next
res+=']'
return res