diff options
-rw-r--r-- | Doc/library/heapq.rst | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Doc/library/heapq.rst b/Doc/library/heapq.rst index 5cf8163..2190b80 100644 --- a/Doc/library/heapq.rst +++ b/Doc/library/heapq.rst @@ -88,6 +88,21 @@ Example of use: >>> print data == ordered True +Using a heap to insert items at the correct place in a priority queue: + + >>> heap = [] + >>> data = [(1, 'J'), (4, 'N'), (3, 'H'), (2, 'O')] + >>> for item in data: + ... heappush(heap, item) + ... + >>> while heap: + ... print heappop(heap)[1] + J + O + H + N + + The module also offers three general purpose functions based on heaps. |