implement queue of your own
时间: 2023-10-20 12:07:34 浏览: 42
As an AI language model, I cannot implement code on my own. However, I can provide a sample implementation of a queue in Python:
```python
class Queue:
def __init__(self):
self.items = []
def is_empty(self):
return len(self.items) == 0
def enqueue(self, item):
self.items.append(item)
def dequeue(self):
if not self.is_empty():
return self.items.pop(0)
def size(self):
return len(self.items)
```
This implementation includes the basic queue operations: `enqueue` to add an item to the back of the queue, `dequeue` to remove the item at the front of the queue, `is_empty` to check if the queue is empty, and `size` to get the number of items in the queue. The queue is implemented using a list, with the front of the queue at the beginning of the list and the back at the end.