Please write the code in Python.
Write a program/function in any Object-Oriented programming language that will implement Queue Abstract Data Type with the following functions/methods. Any build-in/pre-defined Queue function/library (e.g., java.util.Queue in Java) is NOT allowed to use in your code.
Your program/function will do the following steps:
When option (a) is selected, your program should enable grader to enter an element (e.g., TEST1) that will be inserted into the queue, and prompt the main screen to let grader to continue to select any one of options.
When option (b) is selected, your program should remove the element from the queue, and print out the head element (e.g., TEST1) on screen, and prompt the main screen to let grader to continue to select any one of options. If the queue is empty when option (b) is selected, your program should display “There is no element in the queue” on screen and prompt the main screen to let grader to continue to select any one of options.
When option (c) is selected, your program should display the total number of elements in the queue and prompt the main screen to let grader to continue to select any one of options.
When option (d) is selected, your program will be terminated.
Please DO NOT hard-coded any input values, output values in your code.
queue = []
def push():
element=input("Enter value : ")
queue.append(element)
def Pop():
if(len(queue)<=0):
return "There is no element in the queue"
else:
return queue.pop(0)
def count():
return len(queue)
if __name__ == "__main__":
print("1.Push\n2.Pop\n3.Count\n4.Quit")
while(True):
ch=input("Enter choice : ")
if(ch=="push"):
push()
if(ch=="pop"):
print(Pop())
if(ch=="count"):
print(count())
if(ch=="quit"):
break
Get Answers For Free
Most questions answered within 1 hours.