Q. Write a program to insert or delete an element from a Queue depending upon the user's choice. The elements are not shifted after insertion or deletion.

Answer =

queue = [ ]
deleteno = 0
while True :
    print()
    print("Enter your choise as per given -")
    print("1 = For insert data Enter insert ")
    print("2 = For delete data enter delete ")
    print("3 = For Exit  enter exit ")
    print()
    user = input("Enter your choise :- ")
    if user == "insert" :
        data = int(input("Enter the data :- "))
        queue.append(data)
    elif user == "delete" :
        if queue == [ ]:
            print("UnderFlow")
        else :
            queue [ deleteno ] = None
            deleteno =+ 1
    else :
        break
    print("Now our Queue = ",queue)

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post