Skip to content

Commit

Permalink
add comment for top_m
Browse files Browse the repository at this point in the history
  • Loading branch information
shellfly committed Jan 28, 2020
1 parent a620f66 commit 5ade4b0
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion algs4/top_m.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
"""
* Execution: python top_m.py m < input.txt
* Data files: https://algs4.cs.princeton.edu/24pq/tinyBatch.txt
*
* Given an integer m from the command line and an input stream where
* each line contains a String and a long value, this MinPQ client
* prints the m lines whose numbers are the highest.
*
* % python top_m.py 5 < tinyBatch.txt
* Thompson 2/27/2000 4747.08
* vonNeumann 2/12/1994 4732.35
* vonNeumann 1/11/1999 4409.74
* Hoare 8/18/1992 4381.21
* vonNeumann 3/26/2002 4121.85
*
"""

import sys

from algs4.min_pq import MinPQ
Expand All @@ -7,7 +24,6 @@
M = int(sys.argv[1])
pq = MinPQ()
for line in sys.stdin:
Transaction(line)
pq.insert(Transaction(line))
if pq.size() > M:
pq.del_min()
Expand Down

0 comments on commit 5ade4b0

Please sign in to comment.