Mini Shell

Direktori : /opt/imh-python/lib/python3.9/site-packages/pygraph/helpers/classes/
Upload File :
Current File : //opt/imh-python/lib/python3.9/site-packages/pygraph/helpers/classes/priority_queue.py

"""Implements a priority queue class."""

import heapq


class PriorityQueue:
    def __init__(self):
        self.elements = []

    def __str__(self):
        return str(self.elements)

    def __len__(self):
        return len(self.elements)

    def empty(self):
        return len(self.elements) == 0

    def put(self, item, priority):
        heapq.heappush(self.elements, (priority, item))

    def get(self):
        return heapq.heappop(self.elements)[1]

Zerion Mini Shell 1.0