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


You can understand by Watching video :-



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)

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 :- 85
Now our Queue =  [85]

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 :- 56
Now our Queue =  [85, 56]

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 :- 36
Now our Queue =  [85, 56, 36]

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 =  [None, 56, 36]

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 :- 29
Now our Queue =  [None, 56, 36, 29]

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 =  [None, None, 36, 29]

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