def top(self, k): """Generate sequence of top k elements in terms of access count.""" k = min(k, len(self)) temp = PositionalList() for item in self._data: temp.add_last(item) for _ in range(k): highPos = temp.first() walk = temp.after(highPos) while walk is not None: if walk.element()._count > highPos.element()._count: highPos = walk walk = temp.after(walk) yield highPos.element()._value temp.delete(highPos)
def __init__(self): """Create a new empty Priority Queue.""" self._data = PositionalList()
def __init__(self): """Create an empty list of favorites""" self._data = PositionalList()