{"id":83148,"date":"2021-08-09T09:00:27","date_gmt":"2021-08-09T03:30:27","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=83148"},"modified":"2021-08-09T09:00:27","modified_gmt":"2021-08-09T03:30:27","slug":"stack-and-queue-in-c","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/stack-and-queue-in-c\/","title":{"rendered":"Stack in C | Queue in C"},"content":{"rendered":"<p>C programming language offers various types of features and functionalities to the programmers. We learnt how to implement arrays and linked lists in C. So, In this tutorial, we are going to teach you a new and important concept of data structures which is Stack and Queues. Stack and Queue in C are very useful and efficient concept to learn.<\/p>\n<h3>What is Stack in C?<\/h3>\n<p>Stack is known as a linear data structure. It follows the Last-In-First-Out rule. So, if you push something to the stack then the last value which you pushed, will be the first to pop out. The insertion and deletion operation on the stack will only take place from one end which is the top of the stack.<\/p>\n<p>In 2 ways, you can implement a stack in C.<\/p>\n<p><strong>1. Statically:-<\/strong> In C, you can implement a stack using an array. It allows static memory allocation of its data elements. In this, the stack inherits all the features of the array.<\/p>\n<p><strong>2. Dynamically:-<\/strong> You can also implement a stack using a linked list. It allows dynamic memory allocation of its data elements. In this, the stack takes over the characteristics of the linked list.<\/p>\n<h3>Implementing Stack in C using an array:-<\/h3>\n<p>In C, you can implement the stack using an array. And arrays support static memory allocation of its data elements. Before running the program code, you have to declare the size of the array in advance.<\/p>\n<h4>1. Insertion:-<\/h4>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Insertion-in-Stack.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83453\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Insertion-in-Stack.jpg\" alt=\"Insertion in Stack\" width=\"756\" height=\"628\" \/><\/a><\/p>\n<p>The operation for inserting a value into the stack is known as push. If you push something to the stack, it will be added at the top of the stack.<\/p>\n<p><strong>Example of Inserting elements to the stack<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#define SIZE 50\nvoid push()\n{\nint stack[SIZE], top, num;\nif(top == SIZE- 1)\n{\nprintf(\"Please increase the size of the array! If you don't then the stack overflows!\\n\");\n}\nelse\n{\nprintf(\"TechVidvan Tutorial: Pushing a value to the stack!\\n\");\nnum = 20;\ntop++;\nstack[top]=num;\n}\n}<\/pre>\n<h4>2. Deletion in Stack:-<\/h4>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Deletion-in-Stack.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83454\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Deletion-in-Stack.jpg\" alt=\"Deletion in Stack\" width=\"756\" height=\"628\" \/><\/a><\/p>\n<p>The operation for deleting a value from the stack is known as pop. In stack, you can only delete an element from the top of the stack.<\/p>\n<p><strong>Example of Deleting an element from the stack using C<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#define SIZE 50\nvoid pop()\n{\nint stack[SIZE], top, num;\nif(top == -1)\n{\nprintf(\"The Stack is empty\\n\"); \/\/ Stack Underflow!\n}\nelse\n{\nnum=stack[top];\nprintf(\"TechVidvan Tutorial: Popping an element from the stack!\\n\");\nprintf(\"Deleted the %d item.\\n\",stack[top]);\ntop--;\n}\n}<\/pre>\n<h4>3. Display Stack Elements using C<\/h4>\n<p>Stack follows the Last-In-Fast-Out rule. And the data elements of the stack are displayed according to it.<\/p>\n<p><strong>Example of Displaying the elements of the stack<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#define SIZE 50\nvoid print()\n{\nint stack[SIZE], top, n;\nif(top == -1)\n{\nprintf(\"The stack is empty!\\n\"); \/\/ Stack Underflow!\n}\nelse if(top &gt; 0)\n{\nprintf(\"Elements of the stack are:\\n\");\nfor(n = top; n &gt;= 0; n--)\n{\nprintf(\"%d\\n\",stack[n]);\n}\n}\n}<\/pre>\n<h4>Stack Overflow:-<\/h4>\n<p>If the size of the array is exceeding its limit, then stack overflow occurs. If the stack is completely filled with the elements, you cannot insert any element into the stack. Still if you do then you will face stack overflow. Arrays support static memory allocation of its data elements.<\/p>\n<h4>Stack Underflow:-<\/h4>\n<p>If you are displaying the elements of a stack or performing the deletion operation on a stack but the stack is empty then this situation is called Stack Underflow.<\/p>\n<p><strong>Example of Array Implementation of Stack in C<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\n#include &lt;stdlib.h&gt;\n#define SIZE 100\n\nint stack[SIZE];\nint top;\nint a;\nint your_choice;\n\nvoid push();\nvoid pop();\nvoid print();\n\nint main()\n{\n\nprintf(\"TechVidvan Tutorial: Array Implementation of Stack in C!\\n\\n\");\ntop = -1; \/\/ indicating that the stack is empty!\ndo\n{\nprintf(\"1. Insert an Element!\\n2. Delete an Element!\\n3. Display the elements of the stack!\\n4. Please Exit!\\n\\n\");\nprintf(\"Enter your choice from the above: \");\nscanf(\"%d\",&amp;your_choice);\nswitch(your_choice)\n{\ncase 1:\npush();\nbreak;\ncase 2:\npop();\nbreak;\ncase 3:\nprint();\nbreak;\ncase 4:\nexit(0);\nbreak;\ndefault:\nprintf(\"Soory, Please enter a valid choice!\\n\");\nbreak;\n}\n}while(your_choice!=4);\nreturn 0;\n}\nvoid push()\n{\nint value;\nif(top == SIZE- 1)\n{\nprintf(\"The Stack is empty!\\n\");\n}\nelse\n{\nprintf(\"Enter the element to push into the stack: \");\nscanf(\"%d\", &amp;value);\nprintf(\"Element added!\\n\");\ntop++;\nstack[top]=value;\n}\n}\nvoid pop()\n{\nint value;\nif(top == -1)\n{\nprintf(\"The Stack is empty!\\n\");\n}\nelse\n{\nvalue=stack[top];\nprintf(\"Deleted the element: %d\\n\",stack[top]);\nprint(\"Deleted!\\n\");\ntop--;\n}\n}\n\nvoid print()\n{\nif(top == -1)\n{\nprintf(\"The Stack is empty!\\n\");\n}\nelse if(top &gt; 0)\n{\nprintf(\"Elements of the stack are: \\n\");\nfor(a = top; a &gt;= 0; a--)\n{\nprintf(\"%d\\n\",stack[a]);\n}\n}\n}<\/pre>\n<p><strong>Output:-<\/strong><\/p>\n<div class=\"code-output\">TechVidvan Tutorial: Array Implementation of Stack in C!1. Insert an Element!<br \/>\n2. Delete an Element!<br \/>\n3. Display the elements of the stack!<br \/>\n4. Please Exit!Enter your choice from the above: 1<br \/>\nEnter the element to push into the stack: 23<br \/>\nElement added!<br \/>\n1. Insert an Element!<br \/>\n2. Delete an Element!<br \/>\n3. Display the elements of the stack!<br \/>\n4. Please Exit!<\/p>\n<p>Enter your choice from the above: 1<br \/>\nEnter the element to push into the stack: 23<br \/>\nElement added!<br \/>\n1. Insert an Element!<br \/>\n2. Delete an Element!<br \/>\n3. Display the elements of the stack!<br \/>\n4. Please Exit!<\/p>\n<p>Enter your choice from the above: 1<br \/>\nEnter the element to push into the stack: 4<br \/>\nElement added!<br \/>\n1. Insert an Element!<br \/>\n2. Delete an Element!<br \/>\n3. Display the elements of the stack!<br \/>\n4. Please Exit!<\/p>\n<p>Enter your choice from the above: 2<br \/>\nDeleted the element: 4<br \/>\nElements of the stack are:<br \/>\n4<br \/>\n23<br \/>\n23<br \/>\n1. Insert an Element!<br \/>\n2. Delete an Element!<br \/>\n3. Display the elements of the stack!<br \/>\n4. Please Exit!<\/p>\n<p>Enter your choice from the above: 3<br \/>\nElements of the stack are:<br \/>\n23<br \/>\n23<br \/>\n1. Insert an Element!<br \/>\n2. Delete an Element!<br \/>\n3. Display the elements of the stack!<br \/>\n4. Please Exit!<\/p>\n<p>Enter your choice from the above: 4<\/p>\n<\/div>\n<h3>Implementing stack in C using a Linked List:-<\/h3>\n<p>Linked Lists provide dynamic memory allocation of its data elements. In this method, you do not have to declare the size of the stack in advance. You can perform the basic three operations on it such as Insertion, Deletion and Display.<\/p>\n<h4>1. Insertion in Stack using Linked List:-<\/h4>\n<p>You can insert an element into the stack through a linked list.<\/p>\n<p><strong>Example of Inserting an element into the stack<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">void push()\n{\nint value;\nstruct node *ptr = (struct node*)malloc(sizeof(struct node));\nif(ptr == NULL)\n{\nprintf(\"The Stack is Full!\\n\");\n}\nelse\n{\nprintf(\"Enter the element which you want to insert: \");\nscanf(\"%d\",&amp;value);\nif(tmp == NULL)\n{\nptr -&gt; value = value;\nptr -&gt; next = NULL;\ntmp = ptr;\n}\nelse\n{\nptr -&gt; value = ptr;\nptr -&gt; next = tmp;\ntmp = ptr;\n}\n}\n}\n<\/pre>\n<h4>2. Deletion of Stack element using linked list<\/h4>\n<p>You can also delete an element from the stack.<\/p>\n<p><strong>Example of Deleting an element from the stack<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">void pop()\n{\nint element;\nstruct node *ptr;\nif (tmp == NULL)\n{\nprintf(\"The Stack is empty!\\n\");\n}\nelse\n{\nelement = temp -&gt; value;\nptr = tmp;\ntmp = tmp -&gt; next;\nfree(ptr);\nprintf(\"Deleted the element: %d\\n\",element);\n}\n}\n<\/pre>\n<h4>3. Display Stack Elements<\/h4>\n<p>If you want to display the elements of the stack then follow the below code.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">void print()\n{\nint a;\nstruct node *ptr;\nptr = tmp;\nif(ptr == NULL)\n{\nprintf(\"The Stack is empty!\\n\");\n}\nelse\n{\nprintf(\"Elements of the stack are: \\n\");\nwhile(ptr!= NULL)\n{\nprintf(\"%d\\n\",ptr -&gt; value);\nptr = ptr -&gt; next;\n}\n}\n}<\/pre>\n<p><strong>Example of Stack Implementation using Linked Lists<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\n#include &lt;stdlib.h&gt;\n\nvoid push();\nvoid pop();\nvoid print();\nstruct node\n{\nint value;\nstruct node *NEXT;\n};\nstruct node *tmp;\n\nint main()\n{\n\nprintf(\"TechVidvan Tutorial: Stack Implementation using Linked Lists!\\n\\n\");\nint your_choice;\ndo\n{\nprintf(\"1. Insert an element!\\n2. Delete an element!\\n3. Display the elements of the stack!\\n4. Please Exit!\\n\\n\");\nprintf(\"Please enter your choice from the above: \");\nscanf(\"%d\",&amp;your_choice);\n\nswitch(your_choice)\n{\ncase 1:\npush();\nbreak;\ncase 2:\npop();\nbreak;\ncase 3:\nprint();\nbreak;\ncase 4:\nexit(0);\nbreak;\ndefault:\nprintf(\"Sorry, Please choose a invalid choice!\\n\");\nbreak;\n}\n} while(your_choice!=4);\nreturn 0;\n}\n\nvoid push()\n{\nint value;\nstruct node *ptr = (struct node*)malloc(sizeof(struct node));\nif(ptr == NULL)\n{\nprintf(\"The Stack is full!\\n\");\n}\nelse\n{\nprintf(\"Enter the element which you want to push into the stack: \");\nscanf(\"%d\",&amp;value);\nprintf(\"Element added!\\n\");\nif(tmp == NULL)\n{\nptr -&gt; value = value;\nptr -&gt; NEXT = NULL;\ntmp = ptr;\n}\nelse\n{\nptr -&gt; value = value;\nptr -&gt; NEXT = value;\ntmp = ptr;\n}\n}\n}\n\nvoid pop()\n{\nint element;\nstruct node *ptr;\nif (tmp == NULL)\n{\nprintf(\"The Stack is empty!\\n\");\n}\nelse\n{\nelement = tmp -&gt; value;\nptr = tmp;\ntmp = tmp -&gt; NEXT;\nfree(ptr);\nprintf(\"Deleted the element: %d\\n\",element);\nprintf(\"Deleted!\\n\");\n}\n}\nvoid print()\n{\nint a;\nstruct node *ptr;\nptr = tmp;\nif(ptr == NULL)\n{\nprintf(\"The Stack is empty!\\n\");\n}\nelse\n{\nprintf(\"Elements of the stack are: \\n\");\nwhile(ptr!= NULL)\n{\nprintf(\"%d\\n\",ptr-&gt;value);\nptr = ptr -&gt; NEXT;\n}\n}\n}\n<\/pre>\n<p><strong>Output:-<\/strong><\/p>\n<div class=\"code-output\">TechVidvan Tutorial: Stack Implementation using Linked Lists!1. Insert an element!<br \/>\n2. Delete an element!<br \/>\n3. Display the elements of the stack!<br \/>\n4. Please Exit!Please enter your choice from the above: 1<br \/>\nEnter the element which you want to push into the stack: 23<br \/>\nElement added!<br \/>\n1. Insert an element!<br \/>\n2. Delete an element!<br \/>\n3. Display the elements of the stack!<br \/>\n4. Please Exit!<\/p>\n<p>Please enter your choice from the above: 1<br \/>\nEnter the element which you want to push into the stack: 34<br \/>\nElement added!<br \/>\n1. Insert an element!<br \/>\n2. Delete an element!<br \/>\n3. Display the elements of the stack!<br \/>\n4. Please Exit!<\/p>\n<p>Please enter your choice from the above: 1<br \/>\nEnter the element which you want to push into the stack: 56<br \/>\nElement added!<br \/>\n1. Insert an element!<br \/>\n2. Delete an element!<br \/>\n3. Display the elements of the stack!<br \/>\n4. Please Exit!<\/p>\n<p>Please enter your choice from the above: 2<br \/>\nDeleted the element: 56<br \/>\nDeleted!<br \/>\n1. Insert an element!<br \/>\n2. Delete an element!<br \/>\n3. Display the elements of the stack!<br \/>\n4. Please Exit!<\/p>\n<\/div>\n<h3>Applications of Stack in C:-<\/h3>\n<p><strong>1. Number Reversing:-<\/strong> You can easily reverse a sequence of characters or digits.<\/p>\n<p><strong>2. Undo Operation:-<\/strong> In text editors, you can see an undo operation. If you click it then all the changes you made will go back to normal. All the changes are stored into the stack.<\/p>\n<p><strong>3. Infix to Postfix Conversion: With the help of stacks, you can convert<\/strong>\u00a0from infix to postfix.<\/p>\n<p><strong>4. Backtracking:-<\/strong> You can use stacks to solve various maze puzzling problems.<\/p>\n<p><strong>5. Depth First Search:<\/strong>&#8211; With the help of stacks, you can perform a searching algorithm named Depth-First Search.<\/p>\n<h3>What is a Queue in C?<\/h3>\n<p>Queue is known as a linear data structure. It follows the First-In-First-Out rule. So, if you push something to the stack then the first value of the stack will pop out. In the queue, the insertion operation is done from the rear end(back) and the deletion is done from the front.<\/p>\n<p>In 2 ways, you can implement the queue in C.<\/p>\n<p><strong>1. Statically:-<\/strong> In C, you can implement a queue using an array. It allows static memory allocation of its data elements. In this, the queue inherits all the features of the array.<\/p>\n<p><strong>2. Dynamically:-<\/strong> You can also implement a queue using a linked list. It allows dynamic memory allocation of its data elements. In this, the queue takes over the characteristics of the linked list.<\/p>\n<p><strong>NOTE:-<\/strong> You can implement both stacks and queues statically or dynamically. It depends on you.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Queue-block-diagram.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83455\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Queue-block-diagram.jpg\" alt=\"Queue in C\" width=\"720\" height=\"342\" \/><\/a><\/p>\n<h3>Implementing Queue in C using an array:-<\/h3>\n<p>You can implement the queue using an array in C. And arrays support static memory allocation of its data elements. Before running the program code, you have to declare the size of the array in advance.<\/p>\n<p>In the queue, you can perform three basic operations such as insertion, deletion and display.<\/p>\n<h4>1. Insertion in Queue using C<\/h4>\n<p>In the queue, you can insert an element from the rear end of the queue. In queue, insertion of an element is called enqueue.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Inserting-an-element-into-the-queue.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83456\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Inserting-an-element-into-the-queue.jpg\" alt=\"Inserting an element into the queue\" width=\"983\" height=\"628\" \/><\/a><\/p>\n<p><strong>Example of Inserting an element into the queue<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">void enqueue()\n{\nint value;\nif (rear == SIZE - 1)\nprintf(\"The Queue is full!\\n\");\nelse\n{\nif (front == - 1)\nfront = 0;\nprintf(\"Enter the element which you want to insert into the queue: \");\nscanf(\"%d\", &amp;value);\nrear++;\nqueue[rear] = value;\n}\n}\n<\/pre>\n<h4>2. Deletion of queue element using C<\/h4>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Deletion-in-Queue.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83457\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Deletion-in-Queue.jpg\" alt=\"Deletion in Queue\" width=\"907\" height=\"628\" \/><\/a><\/p>\n<p>In the queue, you can only delete an element from the front of the queue. Deletion of an element from the queue is called dequeue.<\/p>\n<p><strong>Example of Deleting an element from the queue<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">void dequeue()\n{\nif (front == - 1 || front &gt; rear)\n{\nprintf(\"The queue is empty! \\n\");\n}\nelse\n{\nprintf(\"Deleted the element: %d\\n\", queue[front]);\nfront++;\n}\n}\n\n<\/pre>\n<h4>3. Display Queue Element<\/h4>\n<p>In C, you can print the elements of the queue according to the FIFO rule.<br \/>\n<strong>Example:- Displaying the elements of the queue<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">void print()\n{\nint a;\nif (front == - 1)\n{\nprintf(\"The queue is empty!\\n\");\n}\nelse\n{\nprintf(\"Elements of the queue are: \\n\");\nfor (a = front; a &lt;= rear; a++)\nprintf(\"%d\\n\", queue[a]);\n}\n}\n<\/pre>\n<p><strong>Example:- Array implementation of queue<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\n#include &lt;stdlib.h&gt;\n\nstruct node\n{\nint data;\nstruct node *next;\n}*front, *rear;\n\nvoid enqueue();\nvoid dequeue();\nvoid print();\n\nint main()\n{\n\nprintf(\"TechVidvan Tutorial: Array implementation of Queue!\\n\\n\");\n\nint your_choice;\ndo\n{\n\nprintf(\"1. Insert an element!\\n2. Delete an element!\\n3. Display the elements of the queue!\\n4. Please Exit!\\n\\n\");\nprintf(\"Enter your your_choice: \");\nscanf(\"%d\",&amp;your_choice);\n\nswitch(your_choice)\n{\ncase 1:\nenqueue();\nbreak;\ncase 2:\ndequeue();\nbreak;\ncase 3:\nprint();\nbreak;\ncase 4:\nexit(0);\nbreak;\ndefault:\nprintf(\"Sorry, Please enter a valid choice!\\n\");\nbreak;\n}\n} while(your_choice!=4);\nreturn 0;\n}\n\nvoid enqueue()\n{\nstruct node *tmp;\n\ntmp = (struct node*)malloc(sizeof(struct node));\nprintf(\"Enter the element which you want to insert: \");\nscanf(\"%d\", &amp;tmp-&gt;data);\nprintf(\"Element added!\\n\");\ntmp-&gt;next = NULL;\nif (rear == NULL)\n{\nfront = rear = tmp;\n}\nelse\n{\nrear-&gt;next = tmp;\nrear = tmp;\n}\n}\n\nvoid dequeue()\n{\nstruct node *tmp;\ntmp = front;\nif (front == NULL)\n{\nprintf(\"The queue is empty!\\n\");\nfront = rear = NULL;\n}\nelse\n{\nprintf(\"Deleted the element: %d\\n\", front-&gt;data);\nprintf(\"Deleted the element!\\n\");\nfront = front-&gt;next;\nfree(tmp);\n}\n}\n\nvoid print()\n{\nstruct node *tmp;\ntmp = front;\nint i = 0;\nif (front == NULL)\n{\nprintf(\"The queue is empty!\\n\");\n}\nelse\n{\nprintf(\"Elements of the stack are:\\n\");\nwhile (tmp)\n{\nprintf(\"%d\\n\", tmp-&gt;data);\ntmp = tmp-&gt;next;\ni++;\n}\n}\n}\n\n<\/pre>\n<p><strong>Output:-<\/strong><\/p>\n<div class=\"code-output\">\n<p>TechVidvan Tutorial: Array implementation of Queue!<\/p>\n<p>1. Insert an element!<br \/>\n2. Delete an element!<br \/>\n3. Display the elements of the queue!<br \/>\n4. Please Exit!<\/p>\n<p>Enter your your_choice: 1<br \/>\nEnter the element which you want to insert: 23<br \/>\nElement added!<br \/>\n1. Insert an element!<br \/>\n2. Delete an element!<br \/>\n3. Display the elements of the queue!<br \/>\n4. Please Exit!<\/p>\n<p>Enter your your_choice: 1<br \/>\nEnter the element which you want to insert: 26<br \/>\nElement added!<br \/>\n1. Insert an element!<br \/>\n2. Delete an element!<br \/>\n3. Display the elements of the queue!<br \/>\n4. Please Exit!<\/p>\n<p>Enter your your_choice: 2<br \/>\nDeleted the element: 23<br \/>\nDeleted the element!<br \/>\n1. Insert an element!<br \/>\n2. Delete an element!<br \/>\n3. Display the elements of the queue!<br \/>\n4. Please Exit!<\/p>\n<p>Enter your your_choice: 1<br \/>\nEnter the element which you want to insert: 54<br \/>\nElement added!<br \/>\n1. Insert an element!<br \/>\n2. Delete an element!<br \/>\n3. Display the elements of the queue!<br \/>\n4. Please Exit!<\/p>\n<p>Enter your your_choice: 3<br \/>\nElements of the stack are:<br \/>\n26<br \/>\n54<br \/>\n1. Insert an element!<br \/>\n2. Delete an element!<br \/>\n3. Display the elements of the queue!<br \/>\n4. Please Exit!<\/p>\n<p>Enter your your_choice: 5<br \/>\nSorry, Please enter a valid choice!<br \/>\n1. Insert an element!<br \/>\n2. Delete an element!<br \/>\n3. Display the elements of the queue!<br \/>\n4. Please Exit!<\/p>\n<p>Enter your your_choice: 4<\/p>\n<\/div>\n<h3>Implementing queue using a Linked List:-<\/h3>\n<p>You can perform dynamic memory allocation of the data elements of the queue using linked lists. In this method, you do not have to declare the size of the queue in advance.<br \/>\nYou can perform the basic three operations on it such as Insertion, Deletion and Display.<br \/>\n<strong>NOTE:-<\/strong> Queue overflow does not exist in the implementation of queues using linked lists.<\/p>\n<h4>1. Insertion in queue using Linked List<\/h4>\n<p>You can also insert an element to the queue using a linked list.<\/p>\n<p><strong>Example:- Inserting an element into the queue<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">void enqueue()\n{\nstruct node *tmp;\ntmp = (struct node*)malloc(sizeof(struct node));\nprintf(\"Enter the element which you want to insert: \");\nscanf(\"%d\", &amp;tmp-&gt;value);\ntmp-&gt;next = NULL;\nif (rear == NULL)\n{\nfront = rear = tmp;\n}\nelse\n{\nrear-&gt;next = tmp;\nrear = tmp;\n}\n}\n\n<\/pre>\n<h4>2. Deletion from queue using linked list<\/h4>\n<p>Below is the code to perform deletion on the queue using the linked list.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">void dequeue()\n{\nstruct node *tmp;\ntmp = front;\nif (front == NULL)\n{\nprintf(\"The queue is empty!\\n\");\nfront = rear = NULL;\n}\nelse\n{\nprintf(\"Deleted the element: %d\\n\", front-&gt;value);\nfront = front-&gt;next;\nfree(tmp);\n}\n}\n\n<\/pre>\n<h4>3. Display queue elements<\/h4>\n<p>You can also display the elements of the queue according to the FIFO rule.<\/p>\n<p><strong>Example:- Displaying the elements inside a queue<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">void print()\n{\nstruct node *tmp;\ntmp = front;\nint i = 0;\nif (front == NULL)\n{\nprintf(\"The queue is empty!\\n\");\n}\nelse\n{\nprintf(\"Elements of the stack are: \\n\");\nwhile (tmp)\n{\nprintf(\"%d\\n\", tmp-&gt;value;\ntmp = tmp-&gt;next;\ni++;\n}\n}\n}<\/pre>\n<p><strong>Example:- Implementation of queue using the linked list<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\n#include &lt;stdlib.h&gt;\n\nstruct node\n{\nint value;\nstruct node *next;\n}*front, *rear;\n\nvoid enqueue();\nvoid dequeue();\nvoid print();\nint main()\n{\n\nprintf(\"TechVidvan Tutorial: Implementing queue using the linked list!\\n\\n\");\n\nint your_choice;\ndo\n{\n\nprintf(\"1. Insert an element!\\n2. Delete an element!\\n3. Display the elements of the queue!\\n4. Please Exit!\\n\\n\");\nprintf(\"Enter a choice from the above ones: \");\nscanf(\"%d\",&amp;your_choice);\n\nswitch(your_choice)\n{\ncase 1:\nenqueue();\nbreak;\ncase 2:\ndequeue();\nbreak;\ncase 3:\nprint();\nbreak;\ncase 4:\nexit(0);\nbreak;\ndefault:\nprintf(\"Sorry, You made an invalid choice!\\n\");\nbreak;\n}\n} while(your_choice!=4);\nreturn 0;\n}\n\nvoid enqueue()\n{\nstruct node *tmp;\n\ntmp = (struct node*)malloc(sizeof(struct node));\nprintf(\"Enter the element which you want to insert: \");\nscanf(\"%d\", &amp;tmp-&gt;value);\nprintf(\"Element added!\\n\");\ntmp-&gt;next = NULL;\nif (rear == NULL)\n{\nfront = rear = tmp;\n}\nelse\n{\nrear-&gt;next = tmp;\nrear = tmp;\n}\n}\n\nvoid dequeue()\n{\nstruct node *tmp;\ntmp = front;\nif (front == NULL)\n{\nprintf(\"The queue is empty!\\n\");\nfront = rear = NULL;\n}\nelse\n{\nprintf(\"Deleted the element: %d\\n\", front-&gt;value);\nprintf(\"Deleted the element!\\n\");\nfront = front-&gt;next;\nfree(tmp);\n}\n}\n\nvoid print()\n{\nstruct node *tmp;\ntmp = front;\nint i = 0;\nif (front == NULL)\n{\nprintf(\"The queue is empty!\\n\");\n}\nelse\n{\nprintf(\"Elements of the queue are:\\n\");\nwhile (tmp)\n{\nprintf(\"%d\\n\", tmp-&gt;value);\ntmp = tmp-&gt;next;\ni++;\n}\n}\n}<\/pre>\n<p><strong>Output:-<\/strong><\/p>\n<div class=\"code-output\">\n<p>TechVidvan Tutorial: Implementing queue using the linked list!<\/p>\n<p>1. Insert an element!<br \/>\n2. Delete an element!<br \/>\n3. Display the elements of the queue!<br \/>\n4. Please Exit!<\/p>\n<p>Enter a choice from the above ones: 1<br \/>\nEnter the element which you want to insert: 21<br \/>\nElement added!<br \/>\n1. Insert an element!<br \/>\n2. Delete an element!<br \/>\n3. Display the elements of the queue!<br \/>\n4. Please Exit!<\/p>\n<p>Enter a choice from the above ones: 1<br \/>\nEnter the element which you want to insert: 24<br \/>\nElement added!<br \/>\n1. Insert an element!<br \/>\n2. Delete an element!<br \/>\n3. Display the elements of the queue!<br \/>\n4. Please Exit!<\/p>\n<p>Enter a choice from the above ones: 1<br \/>\nEnter the element which you want to insert: 6<br \/>\nElement added!<br \/>\n1. Insert an element!<br \/>\n2. Delete an element!<br \/>\n3. Display the elements of the queue!<br \/>\n4. Please Exit!<\/p>\n<p>Enter a choice from the above ones: 2<br \/>\nDeleted the element: 21<br \/>\nDeleted the element!<br \/>\n1. Insert an element!<br \/>\n2. Delete an element!<br \/>\n3. Display the elements of the queue!<br \/>\n4. Please Exit!<\/p>\n<p>Enter a choice from the above ones: 5<br \/>\nSorry, You made an invalid choice!<br \/>\n1. Insert an element!<br \/>\n2. Delete an element!<br \/>\n3. Display the elements of the queue!<br \/>\n4. Please Exit!<\/p>\n<p>Enter a choice from the above ones: 3<br \/>\nElements of the queue are:<br \/>\n24<br \/>\n6<br \/>\n1. Insert an element!<br \/>\n2. Delete an element!<br \/>\n3. Display the elements of the queue!<br \/>\n4. Please Exit!<\/p>\n<p>Enter a choice from the above ones: 4<\/p>\n<\/div>\n<h3>Circular Queue:-<\/h3>\n<p>In the circular queue, the rear end of the queue is equal to the front end of that queue. Using a circular queue, you can avoid the loss of computer memory.<\/p>\n<p>Like the linear queue, you can perform basic operations such as insertion, deletion and displaying the elements of the queue.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Circular-Queue.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83458\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Circular-Queue.jpg\" alt=\"Circular Queue\" width=\"529\" height=\"507\" \/><\/a><\/p>\n<h4>1. Insertion in circular queue<\/h4>\n<p>In the circular queue, you can insert an element into the queue.<\/p>\n<p><strong>Example:- Inserting an element into the circular queue<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">void enqueue()\n{\nif((front == 0 &amp;&amp; rear == SIZE-1) || (front == rear+1))\n{\nprintf(\"The queue is Full!\\n\");\n}\nif (front == -1)\n{\nfront = rear = 0;\n}\nelse\n{\nprintf(\"Enter the element to insert: \");\nscanf(\"%d\", &amp;value);\nif(rear == SIZE-1)\n{\nrear = 0;\n}\nelse\n{\nrear++;\n}\n}\ncircular_queue[rear] = value;\n}<\/pre>\n<h4>2. Deletion from Circular Queue<\/h4>\n<p>In the circular queue, you can also delete an element from it.<\/p>\n<p><strong>Example:- Deleting an element from the circular queue<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">void dequeue()\n{\nif (front == -1)\n{\nprintf(\"The queue is empty!\\n\");\n}\nprintf(\"Deleted the element: %d\\n\",circular_queue[front]);\nif(front == rear)\n{\nfront = rear = -1;\n}\nelse\n{\nif(front == SIZE-1)\n{\nfront = 0;\n}\nelse\nfront++;\n}\n}\n\n<\/pre>\n<h4>3. Display Circular Queue Elements<\/h4>\n<p>To display the elements from the circular queue, you can follow the code below:-<br \/>\n<strong>Example:- Displaying the elements of the circular queue<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">void print()\n{\nint begin_pos = front;\nint end_pos = rear;\nif(front == -1)\n{\nprintf(\"The queue is empty!\\n\");\n}\nprintf(\"Elements of the queue are:\\n\");\nif( begin_pos &lt;= end_pos )\nwhile(begin_pos &lt;= end_pos)\n{\nprintf(\"%d\\n\",circular_queue[begin_pos]);\nbegin_pos++;\n}\nelse\n{\nwhile(begin_pos &lt;= SIZE-1)\n{\nprintf(\"%d\\n\",circular_queue[begin_pos]);\nbegin_pos++;\n}\nbegin_pos = 0;\nwhile(begin_pos &lt;= end_pos)\n{\nprintf(\"%d\\n\",circular_queue[begin_pos]);\nbegin_pos++;\n}\n}\n}<\/pre>\n<p><strong>Example:- Array Implementation of the circular queue<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include&lt;stdio.h&gt;\n#include&lt;stdlib.h&gt;\n#define SIZE 20\n\nint circular_queue[SIZE];\nint your_choice, value;\nint begin_pos, end_pos;\n\nvoid enqueue();\nvoid dequeue();\nvoid print();\n\nint main()\n{\n\nprintf(\"TechVidvan Tutorial: Array Implementation of the circular queue!\\n\\n\");\n\nbegin_pos = end_pos = -1;\ndo\n{\n\nprintf(\"1. Insert an element!\\n2. Delete an element!\\n3. Display the elements from the circular queue!\\n4. Please Exit!\\n\\n\");\nprintf(\"Enter any choice from above: \");\nscanf(\"%d\",&amp;your_choice);\n\nswitch(your_choice)\n{\ncase 1:\nenqueue();\nbreak;\ncase 2:\ndequeue();\nbreak;\ncase 3:\nprint();\nbreak;\ncase 4:\nexit(0);\nbreak;\ndefault:\nprintf(\"Sorry, invalid your_choice!\\n\");\nbreak;\n}\n} while(your_choice!=4);\nreturn 0;\n}\n\nvoid enqueue()\n{\nif((begin_pos == 0 &amp;&amp; end_pos == SIZE-1) || (begin_pos == end_pos+1))\n{\nprintf(\"The queue is full!\\n\");\n}\nif (begin_pos == -1)  \n{\nbegin_pos = end_pos = 0;\n}\nelse\n{\nprintf(\"Enter the element which you want to insert: \");\nscanf(\"%d\", &amp;value);\nprintf(\"Element added!\\n\");\nif(end_pos == SIZE-1)\n{\nend_pos = 0;\n}\nelse\n{\nend_pos++;\n}\n}\ncircular_queue[end_pos] = value ;\n}\n\nvoid dequeue()\n{\nif (begin_pos == -1)\n{\nprintf(\"The queue is empty!\\n\");\n}\nif(begin_pos!= -1)\nprintf(\"Deleted the element: %d\\n\",circular_queue[begin_pos]);\nprintf(\"Element Deleted!\\n\");\nif(begin_pos == end_pos)\n{\nbegin_pos = end_pos = -1;\n}\nelse\n{  \nif(begin_pos == SIZE-1)\n{\nbegin_pos = 0;\n}\nelse\nbegin_pos++;\n}\n}\n\nvoid print()\n{\nint position_at_beginning = begin_pos;\nint position_at_end = end_pos;\nif(begin_pos == -1)\n{\nprintf(\"The queue is empty!\\n\");\n}\nif(begin_pos!= -1)\nprintf(\"Elements of the queue are: \\n\");\nif( position_at_beginning &lt;= position_at_end )\nwhile(position_at_beginning &lt;= position_at_end)\n{\nprintf(\"%d\\n\",circular_queue[position_at_beginning]);\nposition_at_beginning++;\n}\nelse\n{\nwhile(position_at_beginning &lt;= SIZE-1)\n{\nprintf(\"%d\\n\",circular_queue[position_at_beginning]);\nposition_at_beginning++;\n}\nposition_at_beginning = 0;\nwhile(position_at_beginning &lt;= position_at_end)\n{\nprintf(\"%d\\n\",circular_queue[position_at_beginning]);\nposition_at_beginning++;\n}\n}\n}<\/pre>\n<p><strong>Output:-<\/strong><\/p>\n<div class=\"code-output\">\n<p>TechVidvan Tutorial: Array Implementation of the circular queue!<\/p>\n<p>1. Insert an element!<br \/>\n2. Delete an element!<br \/>\n3. Display the elements from the circular queue!<br \/>\n4. Please Exit!<\/p>\n<p>Enter any choice from above: 1<br \/>\n1. Insert an element!<br \/>\n2. Delete an element!<br \/>\n3. Display the elements from the circular queue!<br \/>\n4. Please Exit!<\/p>\n<p>Enter any choice from above: 1<br \/>\nEnter the element which you want to insert: 2<br \/>\nElement added!<br \/>\n1. Insert an element!<br \/>\n2. Delete an element!<br \/>\n3. Display the elements from the circular queue!<br \/>\n4. Please Exit!<\/p>\n<p>Enter any choice from above: 1<br \/>\nEnter the element which you want to insert: 3<br \/>\nElement added!<br \/>\n1. Insert an element!<br \/>\n2. Delete an element!<br \/>\n3. Display the elements from the circular queue!<br \/>\n4. Please Exit!<\/p>\n<p>Enter any choice from above: 1<br \/>\nEnter the element which you want to insert: 4<br \/>\nElement added!<br \/>\n1. Insert an element!<br \/>\n2. Delete an element!<br \/>\n3. Display the elements from the circular queue!<br \/>\n4. Please Exit!<\/p>\n<p>Enter any choice from above: 3<br \/>\nElements of the queue are:<br \/>\n0<br \/>\n2<br \/>\n3<br \/>\n4<br \/>\n1. Insert an element!<br \/>\n2. Delete an element!<br \/>\n3. Display the elements from the circular queue!<br \/>\n4. Please Exit!<\/p>\n<p>Enter any choice from above: 2<br \/>\nDeleted the element: 0<br \/>\nElement Deleted!<br \/>\n1. Insert an element!<br \/>\n2. Delete an element!<br \/>\n3. Display the elements from the circular queue!<br \/>\n4. Please Exit!<\/p>\n<p>Enter any choice from above: 2<br \/>\nDeleted the element: 2<br \/>\nElement Deleted!<br \/>\n1. Insert an element!<br \/>\n2. Delete an element!<br \/>\n3. Display the elements from the circular queue!<br \/>\n4. Please Exit!<\/p>\n<p>Enter any choice from above: 6<br \/>\nSorry, invalid your_choice!<br \/>\n1. Insert an element!<br \/>\n2. Delete an element!<br \/>\n3. Display the elements from the circular queue!<br \/>\n4. Please Exit!<\/p>\n<p>Enter any choice from above: 4<\/p>\n<\/div>\n<h3>Applications of Queue in C:-<\/h3>\n<p>There are various applications of queue. Some of the applications of queue:-<\/p>\n<p><strong>1. Round robin algorithm:-<\/strong> Using the queue, you can perform the round robin algorithm.<\/p>\n<p><strong>2. CPU Scheduling:-<\/strong> With the help of a queue, you can share resources among multiple users at the same time. In a queue, data is processed according to the First-In-First-Out rule.<\/p>\n<p><strong>3. Input-Output Buffers:-<\/strong> Using a queue, you can convert the asynchronous data to synchronous data.<\/p>\n<h3>Difference between Stack and Queue:-<\/h3>\n<table>\n<tbody>\n<tr>\n<td><b>Stack\u00a0<\/b><\/td>\n<td><b>Queue<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Stack follows the Last-In-First-Out rule.<\/span><\/td>\n<td><span style=\"font-weight: 400\">Queue follows the First-In-First-Out rule.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">In stack, you can insert or delete an element only from one end.<\/span><\/td>\n<td><span style=\"font-weight: 400\">In the queue, the insertion is done from the rear of the queue and the deletion is done from the end of the queue.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Here In stack, the insertion operation is called push and the deletion operation is called pop.<\/span><\/td>\n<td><span style=\"font-weight: 400\">In the queue, the insertion operation is called enqueue and the deletion operation is called dequeue.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">We always keep track of the last element of the stack using a pointer called top.<\/span><\/td>\n<td><span style=\"font-weight: 400\">But in the queue, we make use of two pointers. One is pointing to the element inserted at first with the front pointer and second is pointing to the element inserted at last with the rear pointer.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Summary<\/h3>\n<p>In this tutorial, we learnt what stack and queue in C are. We also discussed how to implement a stack and a queue using arrays and linked lists in detail. We also discussed three basic operations which you can perform on both stack and queue. Then we talked about another type of queue named circular queue. We discussed some important applications of both stack and queue. We also talked about the difference between stack and queue.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>C programming language offers various types of features and functionalities to the programmers. We learnt how to implement arrays and linked lists in C. So, In this tutorial, we are going to teach you&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":83445,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3510],"tags":[3993,3994,3995],"class_list":["post-83148","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c-programming","tag-queues-in-c","tag-stack-and-queue-in-c","tag-stacks-in-c"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Stack in C | Queue in C - TechVidvan<\/title>\n<meta name=\"description\" content=\"Learn about Stack and Queue in C with their implementation using arrays and linked lists. Learn their basic operations with eaxmples.\" \/>\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\/stack-and-queue-in-c\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Stack in C | Queue in C - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Learn about Stack and Queue in C with their implementation using arrays and linked lists. Learn their basic operations with eaxmples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/stack-and-queue-in-c\/\" \/>\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-08-09T03:30:27+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Stack-and-Queues-in-C-1.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":"Stack in C | Queue in C - TechVidvan","description":"Learn about Stack and Queue in C with their implementation using arrays and linked lists. Learn their basic operations with eaxmples.","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\/stack-and-queue-in-c\/","og_locale":"en_US","og_type":"article","og_title":"Stack in C | Queue in C - TechVidvan","og_description":"Learn about Stack and Queue in C with their implementation using arrays and linked lists. Learn their basic operations with eaxmples.","og_url":"https:\/\/techvidvan.com\/tutorials\/stack-and-queue-in-c\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2021-08-09T03:30:27+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Stack-and-Queues-in-C-1.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\/stack-and-queue-in-c\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/stack-and-queue-in-c\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Stack in C | Queue in C","datePublished":"2021-08-09T03:30:27+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/stack-and-queue-in-c\/"},"wordCount":2523,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/stack-and-queue-in-c\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Stack-and-Queues-in-C-1.jpg","keywords":["Queues in C","Stack and queue in C","Stacks in C"],"articleSection":["C Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/stack-and-queue-in-c\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/stack-and-queue-in-c\/","url":"https:\/\/techvidvan.com\/tutorials\/stack-and-queue-in-c\/","name":"Stack in C | Queue in C - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/stack-and-queue-in-c\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/stack-and-queue-in-c\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Stack-and-Queues-in-C-1.jpg","datePublished":"2021-08-09T03:30:27+00:00","description":"Learn about Stack and Queue in C with their implementation using arrays and linked lists. Learn their basic operations with eaxmples.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/stack-and-queue-in-c\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/stack-and-queue-in-c\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/stack-and-queue-in-c\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Stack-and-Queues-in-C-1.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Stack-and-Queues-in-C-1.jpg","width":1200,"height":628,"caption":"Stack and Queue in C"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/stack-and-queue-in-c\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Stack in C | Queue in C"}]},{"@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\/83148","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=83148"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/83148\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/83445"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=83148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=83148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=83148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}