{"id":81389,"date":"2021-06-28T09:00:31","date_gmt":"2021-06-28T03:30:31","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=81389"},"modified":"2021-06-28T09:00:31","modified_gmt":"2021-06-28T03:30:31","slug":"queue-in-data-structure","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/queue-in-data-structure\/","title":{"rendered":"Queue in Data Structure"},"content":{"rendered":"<p>The queue data structure is linear. It follows the FIFO approach i.e. First In First Out or Last In Last Out.<br \/>\nIn the queue, the order of insertion is the same as the order of deletion of elements because of the FIFO approach.<\/p>\n<p>Queues are mostly used whenever there is a single resource and multiple users want to use that resource. For example, in threads and CPU scheduling algorithms.<\/p>\n<p>A data structure queue is analogous to a queue in real life. For example, people waiting in a queue to buy movie tickets.<\/p>\n<h3>Representation of a Queue<\/h3>\n<p>Just like a stack, the queue is also an abstract data type but it follows the FIFO approach. In the queue, we always remove the least recently added element.<\/p>\n<p>A queue is open at both ends, unlike a stack. Thus we perform deletion and insertion operations at two different ends in a queue.The two ends of the queue are the <strong>Front<\/strong> and <strong>Rear<\/strong> respectively.<\/p>\n<p>Front points to the index of the queue from where we can delete an element. Rear points to that index of the queue from where we insert elements.<\/p>\n<p>We can represent the queue as follows:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-01.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81428\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-01.jpg\" alt=\"Queue Representation\" width=\"622\" height=\"282\" \/><\/a><\/p>\n<h3>Types of Queue<\/h3>\n<p>There are various types of queue data structures such as:<br \/>\n1. Linear queue<br \/>\n2. Circular queue<br \/>\n3. Deque<br \/>\n4. Priority queue<\/p>\n<p>Let us see each of them in detail now:<\/p>\n<h4>1. Linear queue<\/h4>\n<p>A linear queue is a simple queue in which insertion occurs at one end and deletion occurs at the other end.<br \/>\nIn a linear queue, we are sometimes not able to utilize memory effectively. This is because insertion can be performed only at the rear end.<\/p>\n<h4>Basic operations on Linear Queue:<\/h4>\n<p>The basic operations that we can perform on a queue are:<\/p>\n<p><strong>a. enqueue():<\/strong> To insert an element into the queue.<\/p>\n<p><strong>b. dequeue():<\/strong> To delete an element from a queue.<\/p>\n<p><strong>c. peek():<\/strong> To print\/display the element at the front without deleting it.<\/p>\n<p><strong>d. isfull():<\/strong> To check if the queue is full or not.<\/p>\n<p><strong>e. isempty()<\/strong>: To check if the queue is empty or not.<\/p>\n<p>Out of the given operations, the first two operations are the most important. The rest three are used to improve the efficiency of the first two operations while implementation.<\/p>\n<h5>a. enqueue() Operation in Queue<\/h5>\n<p>The queue has two ends pointed by Front and Rear. The enqueue() operation is always performed at the Rear end.<\/p>\n<p>While performing enqueue() operation, we always check whether the queue is full or not. In case the queue is full, we return an overflow error. Otherwise, we insert the element at the rear end and make the Rear point to the next position in the queue.<\/p>\n<p>For example, suppose we have a queue with elements A, B, C, D and we wish to insert E into the queue. We can insert this new element into the queue as follows:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-02.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81429\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-02.jpg\" alt=\"Enqueue Operation\" width=\"639\" height=\"350\" \/><\/a><\/p>\n<p>The <strong>pseudo-code for the enqueue() operation is shown below:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">void enQueue(int key)  \/\/key is the element to be inserted\n{\n    if(Rear == SIZE-1){   \/\/SIZE denotes the maximum size of the queue\n        print(\"Overflow\");  \/\/Prints overflow if the queue is already full.\n        return;\n    }\n    if(Front == -1){    \/\/If the queue is empty\n        Front = 0;  \/\/whenever the queue is empty, front always point to -1 initially\n        Rear = 0;   \/\/'Queue being empty' is a rare case when both front and rear point to the same index\n        Queue[Rear] = key;\n    }\n    else{\n        Rear = Rear + 1;    \/\/Making rear point to the next index of the queue\n        Queue[Rear] = key;\n    }\n}\n<\/pre>\n<p><strong>The time complexity of enqueue() operation is of the order O(1).<\/strong><\/p>\n<p>Thus, in enqueue operation, we need to remember the following key points:<\/p>\n<p>While performing enqueue() operation algorithmically, we check three different cases. These cases are:<\/p>\n<ul>\n<li>When the queue is empty<\/li>\n<li>When the queue is full<\/li>\n<li>Otherwise<\/li>\n<\/ul>\n<p>When the queue is full, the rear will point to the last index i.e. Size of queue &#8211; 1 position. In that case, we will return an overflow error and exit the program.<\/p>\n<p>When the queue is empty, initially both the front and rear will point to an invalid index say -1. In this case, when we insert an element, both will start pointing to index 0.<\/p>\n<p>Since the queue has only one element, in this case, both the front and rear for a queue will be the same.<\/p>\n<p>If the queue is neither empty nor full, we just increase the value of the rear pointer by one and insert the new element.<\/p>\n<h5>b. dequeue() Operation<\/h5>\n<p>This operation is used to delete an element from the queue. dequeue() operation is always performed at the \u2018Front\u2019 of the queue.<\/p>\n<p>While performing dequeue() operation, we always make sure that the queue is not already empty. If the queue is already empty, there is nothing to delete. In that case, we return an underflow error. If the queue is not empty, we delete the front node and move the front pointer to the next node.<\/p>\n<p>The following diagram depicts the deletion operation:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-03.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81430\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-03.jpg\" alt=\"Dequeue Operation\" width=\"511\" height=\"350\" \/><\/a><\/p>\n<p><strong>The pseudo-code for dequeue() operation is:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int deQueue()\n{\n    int temp;   \/\/We declare 'temp' variable to store the value of element to be deleted\n    if(Front == -1) \/\/If the queue is empty\n    {\n        printf(\"Underflow\");\n        break;\n    }\n    if(Front == Rear)   \/\/If the queue has only one element\n    {\n        temp = Queue[Front];\n        Front = -1;\n        Rear = -1;\n        return temp;\n    }\n    else\n    {\n        temp = Queue[Front];\n        Front = Front + 1;\n        return temp;\n    }\n}\n<\/pre>\n<p>The time complexity of the dequeue() operation is O(1) when we implement the queue using arrays.<\/p>\n<p>In case of dequeue() operation:<\/p>\n<ul>\n<li>If the queue is empty, the Front will be pointing to an invalid index. In this case, we will return the underflow error and exit the program.<\/li>\n<li>If the queue contains only one element, both the Front and Rear will point to the same index. In this case, we will delete the element and make the front and rear point to any invalid index.<\/li>\n<\/ul>\n<h5>c. isfull() Operation in Queue<\/h5>\n<p>Whenever the rear points to the SIZE (i.e. the maximum size of the queue), the isfull() operation returns true.<br \/>\nisfull() operation is a boolean operation i.e. it either returns true or false.<\/p>\n<p>The code for the isfull() operation is as shown below:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">bool isfull() {\n   if(Rear == SIZE-1)\n      return true;\n   else\n      return false;\n}\n\n<\/pre>\n<h5>d. isEmpty() Operation<\/h5>\n<p>It will return true only if the queue is empty. Just like isfull() operation, it is a boolean operation and so it returns either true or false.<\/p>\n<p>If the value of the Front is MIN or pointing to an invalid index, then the queue is empty. Thus, this operation will return true.<\/p>\n<p><strong>The code for isEmpty() operation is:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">bool isEmpty() {\n   if(000Front &lt; 0 || Front &gt; Rear) \n      return true;\n   else\n      return false;\n}\n<\/pre>\n<h5>e. peek() Operation in queue<\/h5>\n<p>This operation returns the value of the data element at the front of the queue without deleting it. Its code will be:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int peek() {\n   return Queue[Front];\n}\n<\/pre>\n<h3>Applications of Linear Queue<\/h3>\n<p>Queues are mainly used for ordering items into a particular order of performance or when there are multiple users for a single resource.<\/p>\n<p>The major applications of the queue data structure are:<\/p>\n<h4>1. Asynchronous data transfer<\/h4>\n<p>We can make use of queues to transfer data asynchronously. Asynchronous transfer means when the rate of transmission of data is not the same between two processes. For example, queues are used in pipes, file input\/output, sockets for asynchronous data transfer.<\/p>\n<h4>2. Multiple users for a single resource<\/h4>\n<p>Whenever we need to make the process wait for a single shared resource, we maintain them inside a queue. For example, printer, CPU, etc are the shared resources.<\/p>\n<h4>3. Used as buffers<\/h4>\n<p>Queues are useful as a buffer to store the data primarily whenever required. For example, the queue is used as a buffer in the case of MP3 players. CD players, etc.<\/p>\n<h4>4. Interrupt handling<\/h4>\n<p>Whenever a process gets interrupted, it is sent back and made to wait in the queue. Thus, queue helps in interrupt handling.<\/p>\n<h4>5. Maintain playlists<\/h4>\n<p>Queues help maintain any kinds of lists. We can maintain a playlist of songs or other media with the help of queues.<\/p>\n<h3>Circular Queue<\/h3>\n<p>A circular queue overcomes the drawback of a linear queue. In the circular queue, all the nodes are in a circle interconnected to each other. The last element of the queue is connected to the first element. It also follows the FIFO approach. It is also known as the <strong>Ring buffer.<\/strong><\/p>\n<h4>Representation of Circular queue:<\/h4>\n<p>Suppose we have the letters of the word \u201cTECHVIDVAN\u201d. It will be represented in the circular queue as follows:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-04.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81431\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-04.jpg\" alt=\"Circular Queue\" width=\"511\" height=\"350\" \/><\/a><\/p>\n<h4>Operations on Circular queue:<\/h4>\n<p>Following are the operations that we can perform on circular queues:<br \/>\n<strong>1. Front( ):<\/strong> It returns the element at which the front pointer is pointing.<br \/>\n<strong>2. Rear( ):<\/strong> It returns the last element of the circular queue.<br \/>\n<strong>3. Enqueue( ):<\/strong> It helps to insert a new element at the rear end of the queue.<br \/>\n<strong>4. Dequeue( ):<\/strong> It deletes the last element of the circular list from the front end.<\/p>\n<h3>Array implementation of Circular queue:<\/h3>\n<h4>1. Enqueue( ):<\/h4>\n<p>If the queue is full, return overflow. If the queue is empty, the rear and front both will point to -1 initially. Insert the new element at 0, and point both front and rear to the 0th index.<\/p>\n<p>Otherwise, insert the lament and increment rear by one.<\/p>\n<p>The pseudo-code will be as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Enqueue_operationint key(){\n    if (rear+1)%max = front\n    {\n        print(\"overflow\");\n        break;\n    }\n    if (front == -1 &amp;&amp; rear == -1)\n    {\n        front = rear = 0;\n        CircularQueue[Rear] = key;\n    }\n    else\n    {\n        Rear = Rear+1;\n        set CircularQueue[Rear] = key;\n    }       \n}\n<\/pre>\n<p><strong>Implementation of Enqueue in C:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">void Enqueue(int key)  \n{  \n    if(Front==-1 &amp;&amp; Rear==-1)  \n    {  \n        Front = Rear = 0;  \n        Counter = 1;\n        CircularQueue[Rear] = key;  \n    }  \n    else if((rear+1) % max == Front)   \n    {  \n        printf(\"OverFlow\");  \n        break;\n    }  \n    else  \n    {  \n        Rear = (Rear+1) % max;       \n        CircularQueue[Rear] = key; \n        Counter++;   \n    }  \n} \n<\/pre>\n<h4>2. Dequeue( ):<\/h4>\n<p>It helps to delete elements from the rear end.<\/p>\n<p>If the queue is already empty, return underflow. Otherwise, delete the element and decrement the value of the rear by one.<\/p>\n<p>While removing the last element, set both front and rear =-1.<\/p>\n<p>The pseudo-code of the dequeue function is:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Dequeue_operation{\n    if (Front == -1)\n    {\n        display(\"underflow\");\n        break;\n    }\n    if (Front == Rear)\n    {\n        Front = Rear = -1;\n    }\n    else{\n        if(Front = SIZE-1)\n            Front = 0\n        else\n            Front = Front + 1\n    }\n}\n<\/pre>\n<p><strong>C implementation of dequeue operation:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int dequeue()  \n{  \n    int Counter=0;\n    if(Front == -1 &amp;&amp; Rear== -1)  \n        printf(\"Underflow\");  \n      \n    else if(Front == Rear)  \n    {    \n        front=-1;  \n        rear=-1; \n        Counter=0; \n    }\n    else    \n        front=(front+1)%max;   \n    return queue[front];\n    Counter--;\n}\n<\/pre>\n<h4>3. size( ):<\/h4>\n<p>This operation returns the size of the circular queue. Its implementation in C is shown below:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int size(int Count) \n    return Count;\n<\/pre>\n<h3>Linked List implementation of Circular queue:<\/h3>\n<p>We can make use of both arrays as well as linked lists to implement a circular queue. But, the linked list implementation is more efficient. The worst-case time complexity of linked list implementation is O(n).<\/p>\n<h4>1. Enqueue( ):<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">void Enqueue(struct Node* NewNode , int key)  \n{  \n    NewNode-&gt;data = key;  \n    Newnode-&gt;Next = 0;  \n    if(Rear==-1)  \n    {  \n        Front = Rear = NewNode;  \n        Rear-&gt;Next = Front;  \n    }  \n    else  \n    {  \n        Rear-&gt;Next = NewNode;  \n        Rear = NewNode;  \n        Rear-&gt;Next = Front;  \n    }  \n}\n<\/pre>\n<h4>2. Dequeue( ):<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">void Dequeue()  \n{  \n    if(Front==-1 &amp;&amp; Rear == -1)  \n    {  \n        printf(\"Underflow\"); \n        break;\n    }  \n    else if(Front == Rear) \n        Front = Rear = -1;   \n    else  \n    {  \n        Front = Front-&gt;Next;  \n        Rear-&gt;Next = Front;  \n    }  \n} \n<\/pre>\n<h4>3. peek( ):<\/h4>\n<p>It returns the value of the element at the front without deleting it.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int peek()  \n{  \n    if(Front==-1 &amp;&amp; Rear==-1)   \n        printf(\"Underflow- EMpty queue\");   \n    else   \n        return Front-&gt;data;  \n}  \n<\/pre>\n<h3>Applications of Circular queue:<\/h3>\n<p>Circular queue comes into use in the following cases:<\/p>\n<h4>1. Memory management<\/h4>\n<p>Circular queues help in better memory management in comparison to linear queues. A circular queue utilizes unused memory very well. This can be shown as follows:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-05.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81434\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-05.jpg\" alt=\"Memory management in Queue\" width=\"358\" height=\"224\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>In this case, even though we have space for 3 elements in the queue, but it will not be able to add the elements. This is because the rear is pointing at the end.<\/p>\n<p>We can overcome this problem using a circular queue as shown:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-06.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81439\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-06.jpg\" alt=\"Circular Queue\" width=\"434\" height=\"350\" \/><\/a><\/p>\n<p>Since it is circular, we can add elements up to the full capacity of the queue.<\/p>\n<h4>2. CPU scheduling<\/h4>\n<p>All the processes waiting for their turn can be placed in a circular queue.<\/p>\n<h4>3. Traffic system<\/h4>\n<p>In computerized traffic systems, circular queues help to switch between the different traffic lights circularly.<\/p>\n<h3>Priority queue:<\/h3>\n<p>In a priority queue, each element has some priority attached to it. This priority decides the order of execution of nodes inside the queue.<\/p>\n<p>A priority queue is designed in such a way that insertion occurs according to the arrival of elements. The deletion occurs on the basis of the priority of execution.<\/p>\n<h4>Types of Priority Queue:<\/h4>\n<p><strong>1. Ascending order priority queue:<\/strong> In ascending priority queue, we give higher priority to a smaller number as shown:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-07.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81432\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-07.jpg\" alt=\"Ascending Queue\" width=\"511\" height=\"182\" \/><\/a><\/p>\n<p><strong>2. Descending order priority queue:<\/strong> It gives high priority to a higher value number.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-08.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81433\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-08.jpg\" alt=\"Descending Queue\" width=\"511\" height=\"182\" \/><\/a><\/p>\n<h4>Implementation of Priority Queue:<\/h4>\n<p>We can implement a priority queue using four different data structures:<br \/>\n1. Array<br \/>\n2. Linked list<br \/>\n3. Binary search tree<br \/>\n4. Heap data structure<\/p>\n<h4>Heap data structure:<\/h4>\n<p>The heap data structure is based on a complete binary tree. It satisfies heap properties. There are two types of heap data structure:<\/p>\n<p><strong>1. Max heap:<\/strong> In a max-heap, for every node, the value of the parent node is greater than both of its child nodes as shown:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-09.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81440\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-09.jpg\" alt=\"Max Heap\" width=\"437\" height=\"283\" \/><\/a><\/p>\n<p><strong>2. Min heap:<\/strong> In a min-heap, the value of every parent node is less than the value of both of its children.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-10.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81441\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-10.jpg\" alt=\"Min Heap\" width=\"437\" height=\"283\" \/><\/a><\/p>\n<h4>Operations on Priority Queue:<\/h4>\n<h5>a. Enqueue operation using Max-heap:<\/h5>\n<p>We first insert the element in the available memory slot such that it does not violate the properties of a complete binary tree. If the element is not at the right place i.e. it violates the max-heap property, we compare it to its parent node.<\/p>\n<p>If the value of the parent node is less than the child node, we swap them. These comparisons and swaps continue until all the nodes are in their right place.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-11.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81442\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-11.jpg\" alt=\"Enqueue using Max Heap\" width=\"437\" height=\"315\" \/><\/a><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-12.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81443\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-12.jpg\" alt=\"Max Heap Enqueue\" width=\"437\" height=\"283\" \/><\/a><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-13.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81444\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-13.jpg\" alt=\"Max heap\" width=\"437\" height=\"283\" \/><\/a><\/p>\n<h5>Time complexity analysis:<\/h5>\n<p>Different data structures generate different time complexities for performing operations on the priority queue.<\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Implementation<\/b><\/td>\n<td><b>Insert\u00a0<\/b><\/td>\n<td><b>Delete\u00a0<\/b><\/td>\n<td><b>peek<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>Linked list<\/b><\/td>\n<td><span style=\"font-weight: 400\">O(1)<\/span><\/td>\n<td><span style=\"font-weight: 400\">O(n)<\/span><\/td>\n<td><span style=\"font-weight: 400\">O(n)<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>Binary heap<\/b><\/td>\n<td><span style=\"font-weight: 400\">O(log n)<\/span><\/td>\n<td><span style=\"font-weight: 400\">O(log n)<\/span><\/td>\n<td><span style=\"font-weight: 400\">O(1)<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>Binary search tree<\/b><\/td>\n<td><span style=\"font-weight: 400\">O(log n)<\/span><\/td>\n<td><span style=\"font-weight: 400\">O(log n)<\/span><\/td>\n<td><span style=\"font-weight: 400\">O(1)<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5>Applications of Priority Queue:<\/h5>\n<p>A priority queue is useful in the following cases:<\/p>\n<p>1. It helps in the implementation of heapsort.<br \/>\n2. It helps in the implementation of the Huffman code.<br \/>\n3. It is used for finding the shortest path in Dijkstra\u2019s algorithm.<br \/>\n4. It is used in Prim\u2019s algorithm.<br \/>\n5. It helps in the implementation of priority scheduling algorithms in the operating system.<\/p>\n<h4>Deque<\/h4>\n<p>Deque stands for <strong>Double Ended Queue. <\/strong>In deque, we can perform deletion and insertion operations from both ends.<\/p>\n<p>The following diagram represents a deque:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-14.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81445\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-14.jpg\" alt=\"Deque Example\" width=\"466\" height=\"145\" \/><\/a><\/p>\n<p>There are two types of deques based on the restrictions imposed:<\/p>\n<p><strong>1. Input-restricted queue:<\/strong> In this type of queue, some restriction is there on the input. We can perform insertion at only one end in an input-restricted queue, but deletion from both ends.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-15.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81446\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-15.jpg\" alt=\"Input Restricted Deque\" width=\"466\" height=\"155\" \/><\/a><\/p>\n<p><strong>2. Output-restricted queue:<\/strong> In this type of queue, we can perform insertion operation at both ends but deletion at only one end. Thus, it has restrictions on deletion operation.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-16.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81447\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-16.jpg\" alt=\"Output Restricted Deque\" width=\"466\" height=\"155\" \/><\/a><\/p>\n<p><strong>3. Behaviour as a stack:<\/strong> deque acts as a stack when both insertion and deletion are restricted from the same end.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-17.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81448\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-17.jpg\" alt=\"Behaviour as stack in queue\" width=\"466\" height=\"186\" \/><\/a><\/p>\n<p><strong>4. Behaviour as a queue:<\/strong> Deque acts as a queue when we restrict insertion from one end and deletion from the other end.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-18.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81449\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-18.jpg\" alt=\"Deque as queue\" width=\"466\" height=\"186\" \/><\/a><\/p>\n<h5>Operations on Deque:<\/h5>\n<p>The basic operations are:<br \/>\n1. Insertion at front<br \/>\n2. Deletion from end<br \/>\n3. Insertion at rear<br \/>\n4. Deletion from rear<br \/>\n5. isFull( )<br \/>\n6. isEmpty( )<\/p>\n<p>We can implement a deque using two data structures:<\/p>\n<ul>\n<li>Linked lists<\/li>\n<li>Circular array<\/li>\n<\/ul>\n<p>A circular array is an array in which the first and the last element are connected to each other as shown:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-19.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81450\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-19.jpg\" alt=\"Circular Queue\" width=\"369\" height=\"350\" \/><\/a><\/p>\n<h3>Array implementation of Deque:<\/h3>\n<h4>a. Enqueue( ):<\/h4>\n<p>If the array is already full, return an overflow error. If the array is empty, set Rear = Front = -1 i.e. make them point to an invalid address.<\/p>\n<p>As we perform the enqueue operation i.e. insert a new element, we increase the value of the rear by 1. If we wish to insert the value at the front, we can apply enqueue operation and decrease the value of the front by 1.<\/p>\n<h4>b. Dequeue( ):<\/h4>\n<p>If the array is already empty, return an underflow error.<\/p>\n<p>To perform the dequeue operation, we delete the element from the front and decrease the value of the front by 1. If we wish to delete the element from the rear end, we apply a dequeue operation and decrease the value of the rear by 1.<\/p>\n<p>If the rear points to the 0th index while deletion operation, delete the lament and make the rear point to the last element of the circular array.<\/p>\n<h4>Working of Deque:<\/h4>\n<p>Let us understand the working of a deque with the help of an example.<\/p>\n<p>Consider an array having a maximum size of 10 and we need to insert the word \u2018TECHVIDVAN\u2019 in it.<\/p>\n<p>1. When the deque is empty, the front and rear will point to -1.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-20.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81451\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-20.jpg\" alt=\"Deque Working\" width=\"600\" height=\"149\" \/><\/a><\/p>\n<p>2. On inserting \u2018T\u2019 at the rear, we will have both front and rear pointing to 0.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-21.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81453\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-21.jpg\" alt=\"Deque working\" width=\"600\" height=\"199\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>3. Insert \u2018E\u2019, \u2018C\u2019 and \u2018H\u2019 at the rear\u00a0 and N at the front as shown:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-22.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81454\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-22.jpg\" alt=\"Deque\" width=\"600\" height=\"168\" \/><\/a>4. Insert \u2018D\u2019 and \u2018A\u2019 at the front.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-23.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81455\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-23.jpg\" alt=\"Insertion in Deque\" width=\"600\" height=\"168\" \/><\/a><\/p>\n<p>5. Perform dequeue( ) operation at both front and rear.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-24.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81456\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-24.jpg\" alt=\"Dequeue Operation\" width=\"600\" height=\"168\" \/><\/a><\/p>\n<p>6. Insert \u2018V\u2019 at the front. Insert \u2018H\u2019, \u2018V\u2019, \u2018I\u2019 and \u2018D\u2019 at the rear.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-25.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81457\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/TV-Queue-normal-images-25.jpg\" alt=\"Insertion in Queue\" width=\"570\" height=\"202\" \/><\/a><\/p>\n<h4>Insertion at the front in Deque:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">void Enqueue_at_Front(int key)  \n{  \n  \n    if(Front==-1 &amp;&amp; Rear==-1)  \n    {  \n        Front = Rear = 0;  \n        deque[Front] = key;  \n    }  \n    else if(Front == 0)  \n    {  \n        Front = SIZE-1;  \n        deque[Front] = key;  \n    }  \n    else  \n    {  \n        Front = Front-1;  \n        deque[Front]= key;  \n    }  \n} \n<\/pre>\n<h4>Insertion at the rear in Deque:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">void Enqueue_at_Rear(int key)  \n{  \n    if(Front==-1 &amp;&amp; rear==-1)  \n    {  \n        Rear=0;  \n        deque[Rear] = key;  \n    }  \n    else if(Rear == SIZE-1)  \n    {  \n        Rear = 0;  \n        deque[Rear] = key;  \n    }  \n    else  \n    {  \n        Rear++;  \n        deque[Rear] = key;  \n    }  \n}\n<\/pre>\n<h4>Dequeue( ) at the front:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">void Dequeue_at_Front()  \n{  \n    if(Front==-1 &amp;&amp; Rear==-1)  \n    {  \n        printf(\"Underflow\");\n        break;\n    }  \n    else if(Front == Rear)  \n    {  \n        printf( deque[Front]);  \n        Front=-1;  \n        Rear=-1;      \n    }  \n     else ifFront == SIZE-1)  \n     {  \n         printf(deque[Front]);  \n         Front = 0;  \n     }  \n     else  \n     {  \n          printf(deque[Front]);  \n          Front = Front+1;  \n     }  \n} \n<\/pre>\n<h4>Dequeue( ) at the end:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">void Dequeue_at_Rear()  \n{  \n    if(Front==-1 &amp;&amp; Rear==-1)  \n    {  \n        printf(\"Underflow\");\n        break;\n    }  \n    else if(Front == Rear)  \n    {  \n        printf(deque[Rear]);  \n        Front = -1;  \n        Rear = -1;  \n          \n    }  \n     else if(Rear == 0)  \n     {  \n         printf(deque[Rear]);  \n         Rear = SIZE-1;  \n     }  \n     else  \n     {  \n          printf(deque[Rear]);  \n          Rear = Rear-1;  \n     }  \n}  \n<\/pre>\n<h4>Get front:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int GetFront()  \n{  \n    if(Front==-1 &amp;&amp; rear==-1)  \n    {  \n        printf(\"Underflow\");  \n        return -1;\n    }  \n    else  \n        return deque[Front];  \n} \n<\/pre>\n<h4>Get rear:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int GetRear()  \n{  \n    if(Front==-1 &amp;&amp; Rear == -1)  \n    {  \n        printf(\"Underflow\"); \n        return -1; \n    }  \n    else  \n       return deque[Rear];  \n} \n\n<\/pre>\n<h4>Applications of Deque:<\/h4>\n<p>1. It can be useful as both stack and queue.<br \/>\n2. It helps to check whether a string is a palindrome or not.<br \/>\n3. It helps in multiprocessor scheduling. It makes use of the <strong>A-steal algorithm<\/strong> for this.<\/p>\n<h3>Linear Queue Implementation in C:<\/h3>\n<h4>Using arrays:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\n#define MAXSIZE 5\n\nvoid Enqueue(int);\nvoid Dequeue();\nvoid Display();\nint items[MAXSIZE], Front=-1, Rear=-1;\nint main() {\n  Enqueue(10);\n  Enqueue(20);\n  Enqueue(30);\n  Enqueue(40);\n  Enqueue(50);\n  Enqueue(60);\n  Display();\n  Dequeue();\n  Display();\n  return 0;\n}\nvoid Enqueue(int val) {\n  if (Rear == MAXSIZE-1)\n    printf(\"Overflow\");\n  else \n  {\n    if(Front == -1)\n      front = 0;\n    Rear++;\n    items[Rear] = val;\n    printf(\"\\nInserted Value -&gt; %d\", val);\n  }\n}\nvoid Dequeue() {\n  if (Front == -1)\n    printf(\"Underflow\");\n  else {\n    printf(\"\\nDeleted Value : %d\", items[Front]);\n    Front++;\n    if (Front &gt; Rear)\n      Front = Rear = -1;\n  }\n}\nvoid Display() {\n  if (Rear == -1)\n    printf(\"Underflow\");\n  else {\n    printf(\"\\nCurrent elements in Queue :\\n\");\n    for (int i = Front; i &lt;= Rear; i++)\n      printf(\"%d  \", items[i]);\n  }\n  printf(\"\\n\");\n}\n<\/pre>\n<h4>Using Linked list:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\n#include &lt;stdlib.h&gt;\n\nstruct QNode {\n    int key;\n    struct QNode* Next;\n};\n\nstruct Queue {\n    struct QNode *Front, *Rear;\n};\n\nstruct QNode* NewNode(int x)\n{\n    struct QNode* temp = (struct QNode*)malloc(sizeof(struct QNode));\n    temp-&gt;key = x;\n    temp-&gt;Next = NULL;\n    return temp;\n}\n\nstruct Queue* CreateQueue()\n{\n    struct Queue* queue = (struct Queue*)malloc(sizeof(struct Queue));\n    queue-&gt;Front = queue-&gt;Rear = NULL;\n    return queue;\n}\n\nvoid enQueue(struct Queue* queue, int x)\n{\n    struct QNode* temp = NewNode(k);\n    if (queue-&gt;Rear == NULL) {\n        queue-&gt;Front = queue-&gt;Rear = temp;\n        return;\n    }\n    queue-&gt;Rear-&gt;Next = temp;\n    queue-&gt;Rear = temp;\n}\n\nvoid deQueue(struct Queue* queue)\n{\n    if (queue-&gt;Front == NULL)   \/\/ If queue is empty, return NULL.\n        return;\n    struct QNode* temp = queue-&gt;Front;\n  \n    queue-&gt;Front = queue-&gt;Front-&gt;Next;\n    if (queue-&gt;Front == NULL)\n        queue-&gt;Rear = NULL;\n    free(temp);\n}\n\nint main()\n{\n    struct Queue* queue = CreateQueue();\n    enQueue(queue, 10);\n    enQueue(queue, 20);\n    deQueue(queue);\n    enQueue(queue, 25);\n    enQueue(queue, 63);\n    deQueue(queue);\n    enQueue(queue, 120);\n    deQueue(queue);\n    printf(\"Queue Front : %d \\n\", queue-&gt;Front-&gt;key);\n    printf(\"Queue Rear : %d\", queue-&gt;Rear-&gt;key);\n    return 0;\n}\n<\/pre>\n<h3>Conclusion<\/h3>\n<p>In this article, we read about the queue data structure, the basic operations performed on the queue, and their implementations. We also read about the use cases and the applications of the queue data structure.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The queue data structure is linear. It follows the FIFO approach i.e. First In First Out or Last In Last Out. In the queue, the order of insertion is the same as the order&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":81427,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3555],"tags":[3641,3642,3643],"class_list":["post-81389","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-structure","tag-deque","tag-operations-on-queue","tag-queue-in-data-structure"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Queue in Data Structure - TechVidvan<\/title>\n<meta name=\"description\" content=\"Learn what is queue in data structure, the basic operations on queue and their implementations with examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/queue-in-data-structure\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Queue in Data Structure - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Learn what is queue in data structure, the basic operations on queue and their implementations with examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/queue-in-data-structure\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-06-28T03:30:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/TV-Queue-in-DS.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"21 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Queue in Data Structure - TechVidvan","description":"Learn what is queue in data structure, the basic operations on queue and their implementations with examples.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/queue-in-data-structure\/","og_locale":"en_US","og_type":"article","og_title":"Queue in Data Structure - TechVidvan","og_description":"Learn what is queue in data structure, the basic operations on queue and their implementations with examples.","og_url":"https:\/\/techvidvan.com\/tutorials\/queue-in-data-structure\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2021-06-28T03:30:31+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/TV-Queue-in-DS.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"21 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/queue-in-data-structure\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/queue-in-data-structure\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Queue in Data Structure","datePublished":"2021-06-28T03:30:31+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/queue-in-data-structure\/"},"wordCount":2574,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/queue-in-data-structure\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/TV-Queue-in-DS.jpg","keywords":["Deque","Operations on Queue","Queue in Data Structure"],"articleSection":["Data Structure Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/queue-in-data-structure\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/queue-in-data-structure\/","url":"https:\/\/techvidvan.com\/tutorials\/queue-in-data-structure\/","name":"Queue in Data Structure - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/queue-in-data-structure\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/queue-in-data-structure\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/TV-Queue-in-DS.jpg","datePublished":"2021-06-28T03:30:31+00:00","description":"Learn what is queue in data structure, the basic operations on queue and their implementations with examples.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/queue-in-data-structure\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/queue-in-data-structure\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/queue-in-data-structure\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/TV-Queue-in-DS.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/TV-Queue-in-DS.jpg","width":1200,"height":628,"caption":"Queue in Data Structure"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/queue-in-data-structure\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Queue in Data Structure"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/81389","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=81389"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/81389\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/81427"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=81389"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=81389"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=81389"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}