queue java

Queue introduction and implementation in Java

Queue is more abstract entity like stack than array and many other data structures. The underlying mechanism used to implement queues is not visible to the user.

In queue first item inserted would be the first one to be removed (First-In-First-Out, FIFO). While in stack as we have seen the last item inserted would be the first one to be removed (LIFO principle).

Queue Operations

The two basic operations of a queue are

  • Inserting an item at the rear of the queue. Insert operation is also called as put or add or enque.
  • Removing an item from front of the queue. Remove operation is also called as delete or get or deque.

Rear of the queue is also called as back or tail or end. The front of the queue is also called as Head.

Application of Queue

Queues are used to model real-world situations like people waiting in a line at a bank ATM to get money, printer queue where many print jobs are waiting in a queue for printers to be available etc.,

Queue implementation in Java

The following program implements a queue in java using a class called MyQueue.

Output

Recommended Posts

References

Leave a Reply

avatar
  Subscribe  
Notify of