Q. Write a program to insert or delete an element from a queue depending upon user's choice.


You can understand by Watching video :-



Answer =
queue = [ ]
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.pop(0)
    else :
        break
    print("Now our Queue = ",queue)

Output :-


Enter your choise as per given -
1 = For insert data Enter insert
2 = For delete data enter delete
3 = For Exit  enter exit

Enter your choise :- insert
Enter the data :- 75
Now our Queue =  [75]

Enter your choise as per given -
1 = For insert data Enter insert
2 = For delete data enter delete
3 = For Exit  enter exit

Enter your choise :- insert
Enter the data :- 45
Now our Queue =  [75, 45]

Enter your choise as per given -
1 = For insert data Enter insert
2 = For delete data enter delete
3 = For Exit  enter exit

Enter your choise :- insert
Enter the data :- 39
Now our Queue =  [75, 45, 39]

Enter your choise as per given -
1 = For insert data Enter insert
2 = For delete data enter delete
3 = For Exit  enter exit

Enter your choise :- delete
Now our Queue =  [45, 39]

Enter your choise as per given -
1 = For insert data Enter insert
2 = For delete data enter delete
3 = For Exit  enter exit

Enter your choise :- delete
Now our Queue =  [39]

Enter your choise as per given -
1 = For insert data Enter insert
2 = For delete data enter delete
3 = For Exit  enter exit

Enter your choise :- exit

>>>

Post a Comment

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

Previous Post Next Post