Like Stack, Queue is a linear structure which follows a particular order in which the operations are performed. The order is First In First Out (FIFO). A good example of queue is any queue of consumers for a resource where the consumer that came first is served first.
The difference between stacks and queues is in removing. In a stack we remove the item the most recently added; in a queue, we remove the item the oldest item on the queue.
Operations on Queue:
Mainly the following two basic operations are performed on queue:
Enqueue: Adds an item to the queue. If the queue is full, then it is said to be an Overflow condition.
Dequeue: Removes an item from the queue. The items are popped in the same order in which they are pushed. If the queue is empty, then it is said to be an Underflow condition.
Some Queue implementations also provide two additional operations:
Front: Get the front item from queue.
Rear: Get the last item from queue.
Notice that they refer to the "rear" of the queue as where we add new items. The "front" is where we pull things off of the queue. This may seem a bit backwards, so make sure you have your terminology correct.
"Queue | Set 1 (Introduction and Array Implementation)" by Soumik Mondal is licensed under CC BY-SA 4.0