Tuesday, 28 January 2020

Queue program menu driven

q=[]
def isEmpty():
       return q == []
def enqueue(i):
    q.append(i)
    print(q)
    return q
def dequeue():
    return q.pop(0)
def size():
    return len(q)
def pr():
        return q
 
while True:
    print('Press a for insert')
    print('Press b for delete')
    print('press c for the size')
    print('Press d for display')
    print('Press e for quit')
   
    op = input('What would you like to do')
    if op == 'a':
        n=int(input("enter a number to push"))
        q=enqueue(n)
    elif op == 'b':
        if isEmpty():
            print('Queue is empty.')
        else:
            print('Deleted value: ',dequeue())
    elif op=='c':
        print(size())
    elif op=='d':
        print(pr())     
    elif op == 'e':
        break                                                                                                                   

No comments:

Post a Comment