Queue Class
Your task is to create a Queue
class in Python that uses a list as its internal data structure. This class should provide the following methods:
enqueue()
: This method takes an input element and adds it to the end of the queue.dequeue()
: This method removes an element from the front of the queue and returns it.size()
: This method returns the current number of elements in the queue.
Please adhere to the following specifications:
The queue should be implemented using a list. This means that the list should not be directly accessible from outside the class.
The
enqueue
method should take one parameter, the element to be added to the queue. It should not return anything.The
dequeue
method should not take any parameters. It should return the element that was removed from the queue. If the queue is empty whendequeue
is called, it should returnNone
.The
size
method should not take any parameters. It should return an integer representing the number of elements currently in the queue.
Input | Output |
---|---|
| 2 a b None |
Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB