What is Queue?
A 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 a queue is any queue of consumers for a resource where the consumer that came first is served first. It takes constant time to add or remove an element in a queue.
Queues should be used over arrays when we need to work with data in the FIFO form.
Dequeue Operation in Queue: In Queue, accessing the content while removing it from the front end of the queue, is known as a Dequeue Operation.
Approach: A Dequeue operation may involve the following steps:
- Checks that the queue is empty or not. If the queue is empty then it produces an error and exit.
- If the queue is not empty then accesses the data element at which front end is pointing.
- Delete the element, using array.pop() operation on buffer.
- Return success.
Example 1: This example implements enqueue operation to create a queue.
After Executing two Dequeue Operations by calling queue1.dequeue() function, the front value changes to 3.
- p5.js | Enqueue Operation in Queue
- jQuery | dequeue() with Examples
- PHP | SplQueue::dequeue() Function
- p5.js | Pop Operation in Stack
- p5.js | Push Operation on Stack
- How to perform click-and-hold operation inside an element using jQuery ?
- jQuery | queue() with Examples
- PHP | Ds\Queue Functions Complete Reference
- 5 Must Have Tools For Web Application Penetration Testing
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.