generate functionFri, 10 Feb 2023

Write a queue class MyQueue with a default constructor and three functions: push(val) - adds a value to the queue, front() - returns the first element in the queue, pop() - removes the first element in the queue.

class MyQueue: def __init__(self): self.data = [] def push(self, val): self.data.append(val) def front(self): if len(self.data) == 0: return -1 return self.data[0] def pop(self): if len(self.data) == 0: return -1 return self.data.pop(0)

Questions about programming?Chat with your personal AI assistant