Why queue is called fifo
By convention, the queue insert operation is called enqueue and the remove operation is called dequeue. Since we are mimicking the Java API, we will stick to the add , offer , poll , and remove. One common model of usage for a queue is to have one thread adding work to the queue, and another processing work from the queue. This is a common way to architect server programs. 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 least recently added.
Complete Interview Preparation Get fulfilled all your interview preparation needs at a single place with the Complete Interview Preparation Course that provides you all the required stuff to prepare for any product-based, service-based, or start-up company at the most affordable prices. Skip to content. Change Language. Related Articles. Table of Contents. Queue is also an abstract data type or a linear data structure, just like stack data structure , in which the first element is inserted from one end called the REAR also called tail , and the removal of existing element takes place from the other end called as FRONT also called head.
Before you continue reading about queue data structure, check these topics before to understand it clearly:. Which is exactly how queue system works in real world. If you go to a ticket counter to buy movie tickets, and are first in the queue, then you will be the first one to get the tickets. Same is the case with Queue data structure. Data inserted first, will leave the queue first.
The process to add an element into queue is called Enqueue and the process of removal of an element from queue is called Dequeue. Queue, as the name suggests is used whenever we need to manage any group of objects in an order in which the first one coming in, also gets out first while the others wait for their turn, like in the following scenarios:.
Queue can be implemented using an Array , Stack or Linked List. The easiest way of implementing a queue is by using an Array. As we add elements to the queue, the tail keeps on moving ahead, always pointing to the position where the next element will be inserted, while the head remains at the first index.
When we remove an element from Queue, we can follow two possible approaches mentioned [A] and [B] in above diagram.
0コメント