Пример #1
0
def hot_potato(names, num):
    q = MyQueue()

    for name in names:
        q.enqueue(name)

    while not q.isEmpty():               
        for x in range(num):
            q.enqueue((q.dequeue()))
        print(q.dequeue() + ' has escaped')
Пример #2
0
def run_simulation(duration, ppm, student_count):
    print_q = MyQueue()
    lab_printer = Printer(ppm)
    wait_times = []

    for cur_time in range(duration):
        if new_print_task(student_count):
            task = Task(cur_time)
            print_q.enqueue(task)

        if (not lab_printer.busy()) and (not print_q.isEmpty()):
            next_task = print_q.dequeue()
            lab_printer.start_next(next_task)
            wait_times.append(next_task.wait_time(cur_time)) 

        lab_printer.tick()

    avg_wait = sum(wait_times) / len(wait_times)

    print('average wait times were %s with %s left in the q' % (avg_wait,print_q.size()))