Queue
- FIFO
- In java the methods of the Queue interface from java.util packages are implement queues in java.
Since interface cannot be instantitated, LinkedList is used to instantitate a Queue object.
- collections.deque are used to impelement in Python. The import statement shall be from collections import deque.
Enqueue
- Adds a new item into the queues
Java:
Queue queue = new LinkedList();
queue.offer = ("Lisa");
Python:
queue = deque([])
queue.append("Lisa")
Dequeue
- Remove the heads of the queue
Java:
Poll();
Python:
popLeft()
Peek
- Retrieves the head of the queue
Java:
peek();
Python:
queue_name[0];
isEmpty
- Check whether the queue is empty
Java:
isEmpty();
Python:
queue = deque([])
if not queue:
print("Queue is not empty");