Esempio n. 1
0
def main():
    b = BoundedQueue(10000)
    c = CircularQueue(10000)
    for i in range(10000):
        b.enqueue(i)
        c.enqueue(i)

    a=time.time()
    for i in range(10000):
        b.dequeue()
    print("bq:",time.time()-a)

    a=time.time()
    for i in range(10000):
        c.dequeue()
    print("cq:",time.time()-a)
Esempio n. 2
0
def main():
    s= BoundedQueue(3)
    while 1:
        c = input("add, serve, or exit:")
        c = c.lower()
        if c == "add":
            i =input("Enter the name of the person to add:")
            try:
                s.enqueue(i)
            except Exception as e:
                print("ERROR: Queue is full")
            else:
                print("add %s to the line"%i)
            finally:
                print("people in the line:",s.all_queue())

        elif c == "serve":
            try:
                i = s.dequeue()
            except Exception as e:
                print("ERROR: Queue is empty")
            else:
                print('%s has been served'%i)
            finally:
                print("people in the line:",s.all_queue())

        elif c == "exit":
            print('bye')
            import sys
            sys.exit()
        else:
            print("wrong!")