Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between "enqueue" and "dequeue"

Can somebody please explain the main differences? I don't have a clear knowledge about these functions in programming for any language.

like image 668
Omar Avatar asked May 08 '13 05:05

Omar


People also ask

What are enqueue and dequeue operations in queue?

Queue is an abstract data structure, somewhat similar to Stacks. Unlike stacks, a queue is open at both its ends. One end is always used to insert data (enqueue) and the other is used to remove data (dequeue). Queue follows First-In-First-Out methodology, i.e., the data item stored first will be accessed first.

What is enqueue and dequeue in C++?

EnQueue: Adds an item to the queue. Addition of an item to the queue is always done at the rear of the queue. DeQueue: Removes an item from the queue. An item is removed or de-queued always from the front of the queue. isEmpty: Checks if the queue is empty.

What is enqueue and dequeue in Java?

The process of adding an element at the back of the Queue is called Enqueue, and the process of removing an element from the front of the Queue is called Dequeue.

What is the difference between basic queue and double-ended queue?

As the name indicates, Deque is a double-ended queue that is the implementation of the simple Queue. Still, the insertion and deletion of elements take place from both the ends. In contrast, Queue is a data structure where the insertion and deletion of elements take place only from the rear and front end, respectively.


1 Answers

Some of the basic data structures in programming languages such as C and C++ are stacks and queues.

The stack data structure follows the "First In Last Out" policy (FILO) where the first element inserted or "pushed" into a stack is the last element that is removed or "popped" from the stack.

Similarly, a queue data structure follows a "First In First Out" policy (as in the case of a normal queue when we stand in line at the counter), where the first element is pushed into the queue or "Enqueued" and the same element when it has to be removed from the queue is "Dequeued".

This is quite similar to push and pop in a stack, but the terms enqueue and dequeue avoid confusion as to whether the data structure in use is a stack or a queue.

Class coders has a simple program to demonstrate the enqueue and dequeue process. You could check it out for reference.

http://classcoders.blogspot.in/2012/01/enque-and-deque-in-c.html

like image 59
Flipsyde Avatar answered Oct 10 '22 08:10

Flipsyde