Q. Write a program to implement input-restricted deque. (Both the operations i.e., insertions and deletion should be taken care of)

Answer =


You can understand by Watching video :-



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

Output :-

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

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

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

Enter your choise :- insert
Enter the data :- 63
Now our Queue =  [57, 63]

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

Enter your choise :- insert
Enter the data :- 71
Now our Queue =  [57, 63, 71]

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

Enter your choise :- insert
Enter the data :- 5
Now our Queue =  [57, 63, 71, 5]

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

Enter your choise :- front
Now our Queue =  [63, 71, 5]

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

Enter your choise :- back
Now our Queue =  [63, 71]

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

Enter your choise :- insert
Enter the data :- 2
Now our Queue =  [63, 71, 2]

Enter your choise as per given -
1 = For insert data Enter insert
2 = For delete data from front enter front
3 = For delete data from front enter back
4 = 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