def main(prt=sys.stdout):
  """Unit tests the MinPQ data type."""
  pq = MinPQ()
  """Read stdin until ctrl-D is seen."""
  for item in fileinput.input():
    item = item.rstrip("\n\r")
    if item != "-": 
      pq.insert(item)
    elif not pq.isEmpty(): 
      prt.write("{} ".format(pq.delMin()))
  prt.write("({SZ}) left on pq)".format(SZ=pq.size()))
def main(prt=sys.stdout):
  """Unit tests the <tt>MinPQ</tt> data type."""
  pq = MinPQ()
  """Read stdin until ctrl-D is seen."""
  for item in fileinput.input():
    item = item.rstrip("\n\r")
    if item != "-": 
      pq.insert(item)
    elif not pq.isEmpty(): 
      prt.write("{} ".format(pq.delMin()))
  prt.write("({SZ}) left on pq)".format(SZ=pq.size()))
Beispiel #3
0
def main(prt=sys.stdout):
    """Reads seq from stdin; takes args M; prints the M largest in decending order."""
    M = int(sys.argv[1])  # The max # of elems to be stored at one time.
    pq = MinPQ(M + 1)

    # Read stdin until ctrl-D is seen.
    for line in fileinput.input(sys.argv[2:]):
        pq.insert(Transaction(line.rstrip("\n\r")))
        if pq.size() > M:  # rm min if M+1 entries on the PQ
            pq.delMin()

    # Print entries on PQ in reverse order
    stack = Stack()
    for transaction in pq:
        stack.push(transaction)
    for transaction in stack:
        prt.write("{}\n".format(transaction))