/PriorityQueue.py Secret
Created
July 22, 2022 07:26
힙으로 구현한 우선순위 큐
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Heap(): | |
... | |
class PQueue(): | |
def __init__(self, pc): | |
self.heap = Heap(pc) | |
def isEmpty(self) -> bool: | |
return self.heap.HIsEmpty() | |
def enqueue(self, data: HData) -> None: | |
return self.heap.HInsert(data) | |
def dequeue(self) -> HData: | |
return self.heap.HDelete() | |
def dataPriorityComp(ch1: str, ch2: str): | |
return ord(ch2) - ord(ch1) | |
pq = PQueue(dataPriorityComp) | |
pq.enqueue(HData("A")) | |
pq.enqueue(HData("B")) | |
pq.enqueue(HData("C")) | |
while pq.isEmpty() != True: | |
print(pq.dequeue()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment