1
1
from Heap .BinaryHeap .maxHeap import MaxHeap
2
2
from copy import deepcopy
3
3
4
-
5
4
class PriorityQueue (object ):
6
5
def __init__ (self , pq_capacity = 10 ):
7
6
self ._pq_capacity_ = pq_capacity
@@ -12,7 +11,7 @@ def __init__(self, pq_capacity=10):
12
11
def insert (self , item , priority ):
13
12
res = False
14
13
if self .is_full ():
15
- print "Priority queue is full, please delete older items in order to insert newer ones."
14
+ print ( "Priority queue is full, please delete older items in order to insert newer ones." )
16
15
return res
17
16
e = Entry (item , priority )
18
17
res = self ._pq_heap_ .insert (e )
@@ -24,7 +23,7 @@ def insert(self, item, priority):
24
23
def delete_item_with_highest_priority (self ):
25
24
res = False
26
25
if self .is_empty ():
27
- print "Priority queue is empty"
26
+ print ( "Priority queue is empty" )
28
27
return res
29
28
res = self ._pq_heap_ .delete_max ()
30
29
if isinstance (res , bool ) and res == False :
@@ -36,7 +35,7 @@ def delete_item_with_highest_priority(self):
36
35
# Time Complexity : O(1)
37
36
def get_item_with_highest_priority (self ):
38
37
if self .is_empty ():
39
- print "Priority queue is empty"
38
+ print ( "Priority queue is empty" )
40
39
return False
41
40
return self ._pq_heap_ .get_max ()
42
41
@@ -104,9 +103,9 @@ def test():
104
103
mh_test .insert (priority )
105
104
pq .insert (item , priority )
106
105
107
- print pq .pq_arr ()
108
- print mh_test .heap_arr ()
109
- print "Element with highest priority: " , pq .get_item_with_highest_priority ()
106
+ print ( pq .pq_arr () )
107
+ print ( mh_test .heap_arr () )
108
+ print ( "Element with highest priority: " , pq .get_item_with_highest_priority () )
110
109
111
110
112
111
if __name__ == '__main__' :
@@ -122,40 +121,40 @@ def test():
122
121
5. Get the size and capacity of priority queue.
123
122
6. Stop.
124
123
"""
125
- print menu
124
+ print ( menu )
126
125
while True :
127
126
try :
128
127
choice = input ("Please enter your choice - " )
129
128
except :
130
- print "Incorrect choice, please select from menu."
129
+ print ( "Incorrect choice, please select from menu." )
131
130
continue
132
131
try :
133
132
if choice == 1 :
134
- item_priority = raw_input ("Enter item & priority separated by a white-space - " )
133
+ item_priority = input ("Enter item & priority separated by a white-space - " )
135
134
item_priority = item_priority .split (" " )
136
135
item = item_priority [0 ].strip ()
137
136
priority = item_priority [1 ].strip ()
138
137
res = pq .insert (item , priority )
139
- print res
138
+ print ( res )
140
139
continue
141
140
if choice == 2 :
142
- print pq .pq_print ()
141
+ print ( pq .pq_print () )
143
142
continue
144
143
if choice == 3 :
145
144
res = pq .get_item_with_highest_priority ()
146
- print res
145
+ print ( res )
147
146
continue
148
147
if choice == 4 :
149
148
res = pq .delete_item_with_highest_priority ()
150
- print res
149
+ print ( res )
151
150
continue
152
151
if choice == 5 :
153
- print "Size : {} | Capacity: {}" .format (pq .pq_size (), pq .pq_capacity ())
152
+ print ( "Size : {} | Capacity: {}" .format (pq .pq_size (), pq .pq_capacity () ))
154
153
continue
155
154
if choice == 6 :
156
155
break
157
156
except Exception as ex :
158
- print "Error occurred while performing last operation(choice: {}):" .format (choice )
159
- print ex .message , ex .args
157
+ print ( "Error occurred while performing last operation(choice: {}):" .format (choice ) )
158
+ print ( ex .message , ex .args )
160
159
161
- print menu
160
+ print ( menu )
0 commit comments