A queue is a data structure used for storing data (similar to Linked Lists and Stacks). In a queue, the order in which data arrives is important. In general, a queue is a line of people or things waiting to be served in sequential order starting at the beginning of the line or sequence.
A queue is an ordered list in which insertions are done at one end (rear) and deletions are done at other ends (front). The first element to be inserted is the first one to be deleted. Hence, it is called First In First Out (FIFO) or Last In Last Out (LILO) list.
The following operations make a queue an ADT. Insertions and deletions in a queue must follow the FIFO scheme. For simplicity, we assume the elements are integers.
Main Queue Operations:
- enQueue(int data): Inserts an element at the end of the queue
- int deQueue(): Removes and returns the element at the front of the queue.
- Operating systems schedule jobs (with equal priority) in the order of arrival (e.e a print queue).
- Simulation of real-world queues such as lines at a ticket counter, or any other first-come first-served scenario requires a queue.
- Asynchronous data transfer (file IO, pipes, sockets).
- Waiting times for a customer at a call center.
- Determining the number of cashiers to have at a supermarket.
source: Data Structures and Algorithms Made Easy in Java ( By Narasimha Karumanchi )