-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyalgorithm.py
More file actions
22 lines (22 loc) · 810 Bytes
/
Copy pathmyalgorithm.py
File metadata and controls
22 lines (22 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class PriorityQueue :
def __init__( self ):
self._qList = list()
def isEmpty( self ):
return len( self ) == 0
def __len__( self ):
return len( self._qList )
def enqueue( self, item, priority ):
entry = _PriorityQEntry( item, priority )
self._qList.append( entry )
def dequeue( self ) :
assert not self.isEmpty(), "Cannot dequeue from an empty queue."
highest = self._qList[i].priority
for i in range( self.len() ) :
if self._qList[i].priority < highest :
highest = self._qList[i].priority
entry = self._qList.pop( highest )
return entry.item
class _PriorityQEntry( object ):
def __init__( self, item, prioity ):
self.item = item
self.priority = priority