zoukankan      html  css  js  c++  java
  • python for unbounded priority queue

    class _PriorityQEntry:
        def __init__(self, item, priority):
            self.item = item
            self.priority = priority
    
    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[0].priority
            for i in range(self.len()):
                if self._qList[i] < highest:
                    highest = self._qList[i].priority
            entry = self._qList.pop(i)
            return entry.item
  • 相关阅读:
    HDU 5444 Elven Postman 二叉排序树
    HDU 5438 Ponds dfs模拟
    Gym
    markdown test
    Gym
    集训回顾
    UVALive
    UVALive
    UVALive
    codeforcres 589 J
  • 原文地址:https://www.cnblogs.com/ningjing213/p/14121801.html
Copyright © 2011-2022 走看看