Q. Write Insert(City) and Delete(City) methods in Python to add City and Remove City considering them to act as Insert and Delete operations of the data structure Queue.


Answer :-

def insert(City) :
      queue.append(City)

def Delete(City) :
      queue.pop(0)
      
queue = [ ]
while True :
      print()
      print("Enter your choice 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 choice :- ")
      if user == "insert" :
            City = input("Enter City Name :- ")
            insert(City)
      elif user == "delete" :
            if queue == [ ]:
                  print("UnderFlow")
            else :
                  Delete(City)
      else :
            break
print("Now our Queue = ",queue)

Output :-


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

Enter your choice :- insert
Enter City Name :- Path

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

Enter your choice :- insert
Enter City Name :- Walla

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

Enter your choice :- insert
Enter City Name :- Portal

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

Enter your choice :- delete

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

Enter your choice :- insert
Enter City Name :- Express

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

Enter your choice :- delete

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

Enter your choice :- exit
Now our Queue =  ['Portal', 'Express']

>>>


Post a Comment

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

Previous Post Next Post