Data Structures || Important Questions || Sumita-Arora || Preeti-Arora || Computer Science || Class 12


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


Answer =
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)


Post a Comment

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

Previous Post Next Post