{"id":8762,"date":"2022-06-29T11:50:30","date_gmt":"2022-06-29T11:50:30","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=8762"},"modified":"2023-09-22T10:28:26","modified_gmt":"2023-09-22T10:28:26","slug":"circular-queue-in-data-structure","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/circular-queue-in-data-structure\/","title":{"rendered":"Circular Queue in Data Structure"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1674633612908-Circular%20Queue%20in%20Data%20Structure.jpg\" alt=\"\" \/><\/p>\n<p>In this Blog, we will talk about circular queue in data structure. We will cover the multiple approaches to implement circular queue in data structure. Also we will see the applications of circular queue in data structure. Circular queue is an efficient data structure in comparison with a simple queue as it doesn&#8217;t waste the space allotted to it. <\/p>\n<p>Lets see What Is Circular Queue in Data Structure?<\/p>\n<h2>What is Circular Queue in Data Structure?<\/h2>\n<p>A circular queue in data structures is a linear arrangement that adheres to the principle of First In First Out (FIFO). Within this structure, the final element is linked to the initial element, creating a circular connection that forms a ring-like configuration, often referred to as a Ring buffer.<\/p>\n<h3>How does the Circular queue in data structure work?<\/h3>\n<p>A circular queue in data structure works in the process of circular increment i.e. when we\u2019ll increment the pointer and reach the end then pointer points to the beginning of the queue.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1656308533880-Image-01%20%281%29.png\" alt=\"\" \/> <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1656498555376-Image-02.png\" alt=\"\" \/> <\/p>\n<h3>Operations of a Circular Queue in Data Structure:<\/h3>\n<ul>\n<li><strong>front():<\/strong> front is used to track the first element of the queue.<\/li>\n<li><strong>rear():<\/strong> rear is used to track the last element of the queue.<\/li>\n<li><strong>Enqueue:<\/strong> This operation is used to Insert an element at the end of the queue.<\/li>\n<li><strong>Dequeue:<\/strong> This operation is used to remove and return an element from the front of the queue.<\/li>\n<\/ul>\n<p><strong>Steps for Enqueue Operation:<\/strong><\/p>\n<ul>\n<li>Check if the queue is full.<\/li>\n<li>If the queue is full then, the print queue is full.<\/li>\n<li>If not, check the condition(rear == size -1 &amp;&amp; front != 0)<\/li>\n<li>If it is true then set the rear = 0 and insert the new element.<\/li>\n<\/ul>\n<h3>Algorithm to Insert an Element in a Circular Queue in Data Structure<\/h3>\n<p><strong>Step 1:<\/strong> IF (REAR+1)%MAX = FRONT<br \/>\nWrite &quot; OVERFLOW &quot;<br \/>\nGoto step 4<br \/>\n[End OF IF]<\/p>\n<p><strong>Step 2:<\/strong> IF FRONT = -1 and REAR = -1<br \/>\nSET FRONT = REAR = 0<br \/>\nELSE IF REAR = MAX &#8211; 1 and FRONT ! = 0<br \/>\nSET REAR = 0<br \/>\nELSE<br \/>\nSET REAR = (REAR + 1) % MAX<br \/>\n[END OF IF]<\/p>\n<p><strong>Step 3:<\/strong> SET QUEUE[REAR] = VAL<\/p>\n<p><strong>Step 4:<\/strong> EXIT<\/p>\n<p><strong>Steps for Dequeue Operations:<\/strong><\/p>\n<ul>\n<li>Firstly, check whether the queue is empty or not.<\/li>\n<li>If the queue is empty then display the queue is empty.<\/li>\n<li>If not, check the condition(rear == front)<\/li>\n<li>If the condition is true then set front = rear = -1.<\/li>\n<li>Else, front == size-1 and return the element.<\/li>\n<\/ul>\n<h3>Algorithm to Delete an Element from the Circular Queue in Data Structure<\/h3>\n<p><strong>Step 1:<\/strong> IF FRONT = -1<br \/>\nWrite &quot; UNDERFLOW &quot;<br \/>\nGoto Step 4<br \/>\n[END of IF]<\/p>\n<p><strong>Step 2:<\/strong> SET VAL = QUEUE[FRONT]<\/p>\n<p><strong>Step 3:<\/strong> IF FRONT = REAR<br \/>\nSET FRONT = REAR = -1<br \/>\nELSE<br \/>\nIF FRONT = MAX -1<br \/>\nSET FRONT = 0<br \/>\nELSE<br \/>\nSET FRONT = FRONT + 1<br \/>\n[END of IF]<br \/>\n[END OF IF]<\/p>\n<p><strong>Step 4:<\/strong> EXIT<\/p>\n<p><strong>Code Implementation<\/strong><\/p>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_12145 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_12145 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_12145 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_12145 .wpsm_nav-tabs > li.active > a, #tab_container_12145 .wpsm_nav-tabs > li.active > a:hover, #tab_container_12145 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_12145 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_12145 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_12145 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_12145 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_12145 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_12145 .wpsm_nav-tabs > li > a:hover , #tab_container_12145 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_12145 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_12145 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_12145 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_12145 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_12145 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_12145 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_12145 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_12145 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_12145 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_12145 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_12145 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_12145\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_12145\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_12145_1\" aria-controls=\"tabs_desc_12145_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C++<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_12145_2\" aria-controls=\"tabs_desc_12145_2\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>Java<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_12145_3\" aria-controls=\"tabs_desc_12145_3\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>Python<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_12145\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_12145_1\">\r\n\t\t\t\t\t\t\t\t<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\">#include&lt;bits\/stdc++.h&gt;\r\nusing namespace std;\r\n\r\nclass Queue\r\n{\r\n    int rear, front;\r\n\r\n\r\n    int size;\r\n    int *arr;\r\npublic:\r\n    Queue(int s)\r\n    {\r\n    front = rear = -1;\r\n    size = s;\r\n    arr = new int[s];\r\n    }\r\n\r\n    void enQueue(int value);\r\n    int deQueue();\r\n    void displayQueue();\r\n};\r\n\r\n\r\nvoid Queue::enQueue(int value)\r\n{\r\n    if ((front == 0 &amp;&amp; rear == size-1) ||\r\n            (rear == (front-1)%(size-1)))\r\n    {\r\n        printf(\"&#92;nQueue is Full\");\r\n        return;\r\n    }\r\n\r\n    else if (front == -1)\r\n    {\r\n        front = rear = 0;\r\n        arr[rear] = value;\r\n    }\r\n\r\n    else if (rear == size-1 &amp;&amp; front != 0)\r\n    {\r\n        rear = 0;\r\n        arr[rear] = value;\r\n    }\r\n\r\n    else\r\n    {\r\n        rear++;\r\n        arr[rear] = value;\r\n    }\r\n}\r\n\r\nint Queue::deQueue()\r\n{\r\n    if (front == -1)\r\n    {\r\n        printf(\"&#92;nQueue is Empty\");\r\n        return INT_MIN;\r\n    }\r\n\r\n    int data = arr[front];\r\n    arr[front] = -1;\r\n    if (front == rear)\r\n    {\r\n        front = -1;\r\n        rear = -1;\r\n    }\r\n    else if (front == size-1)\r\n        front = 0;\r\n    else\r\n        front++;\r\n\r\n    return data;\r\n}\r\n\r\n\r\nvoid Queue::displayQueue()\r\n{\r\n    if (front == -1)\r\n    {\r\n        printf(\"&#92;nQueue is Empty\");\r\n        return;\r\n    }\r\n    printf(\"&#92;nElements in Circular Queue are: \");\r\n    if (rear &gt;= front)\r\n    {\r\n        for (int i = front; i &lt;= rear; i++)\r\n            printf(\"%d \",arr[i]);\r\n    }\r\n    else\r\n    {\r\n        for (int i = front; i &lt; size; i++)\r\n            printf(\"%d \", arr[i]);\r\n\r\n        for (int i = 0; i &lt;= rear; i++)\r\n            printf(\"%d \", arr[i]);\r\n    }\r\n}\r\n\r\nint main()\r\n{\r\n    Queue q(5);\r\n\r\n    \/\/ Inserting elements in Circular Queue\r\n    q.enQueue(40);\r\n    q.enQueue(22);\r\n    q.enQueue(30);\r\n    q.enQueue(-7);\r\n\r\n    q.displayQueue();\r\n\r\n    printf(\"&#92;nDeleted value = %d\", q.deQueue());\r\n    printf(\"&#92;nDeleted value = %d\", q.deQueue());\r\n\r\n    q.displayQueue();\r\n\r\n    q.enQueue(90);\r\n    q.enQueue(20);\r\n    q.enQueue(5);\r\n\r\n    q.displayQueue();\r\n\r\n    q.enQueue(20);\r\n    return 0;\r\n}\r\n<\/pre>\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_12145_2\">\r\n\t\t\t\t\t\t\t\t<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\">import java.util.ArrayList;\r\n\r\nclass CircularQueue{\r\n\r\nprivate int size, front, rear;\r\n\r\nprivate ArrayList&lt;Integer&gt; queue = new ArrayList&lt;Integer&gt;();\r\n\r\n\r\nCircularQueue(int size)\r\n{\r\n    this.size = size;\r\n    this.front = this.rear = -1;\r\n}\r\n\r\npublic void enQueue(int data)\r\n{\r\n    \r\n\r\n    if((front == 0 &amp;&amp; rear == size - 1) ||\r\n    (rear == (front - 1) % (size - 1)))\r\n    {\r\n        System.out.print(\"Queue is Full\");\r\n    }\r\n\r\n    else if(front == -1)\r\n    {\r\n        front = 0;\r\n        rear = 0;\r\n        queue.add(rear, data);\r\n    }\r\n\r\n    else if(rear == size - 1 &amp;&amp; front != 0)\r\n    {\r\n        rear = 0;\r\n        queue.set(rear, data);\r\n    }\r\n\r\n    else\r\n    {\r\n        rear = (rear + 1);\r\n    \r\n        if(front &lt;= rear)\r\n        {\r\n            queue.add(rear, data);\r\n        }\r\n    \r\n        else\r\n        {\r\n            queue.set(rear, data);\r\n        }\r\n    }\r\n}\r\n\r\n\r\npublic int deQueue()\r\n{\r\n    int temp;\r\n\r\n    if(front == -1)\r\n    {\r\n        System.out.print(\"Queue is Empty\");\r\n        \r\n        \/\/ Return -1 in case of empty queue\r\n        return -1;\r\n    }\r\n\r\n    temp = queue.get(front);\r\n\r\n    if(front == rear)\r\n    {\r\n        front = -1;\r\n        rear = -1;\r\n    }\r\n\r\n    else if(front == size - 1)\r\n    {\r\n        front = 0;\r\n    }\r\n    else\r\n    {\r\n        front = front + 1;\r\n    }\r\n    \r\n    \/\/ Returns the dequeued element\r\n    return temp;\r\n}\r\n\r\n\/\/ Method to display the elements of queue\r\npublic void displayQueue()\r\n{\r\n    \r\n    \/\/ Condition for empty queue.\r\n    if(front == -1)\r\n    {\r\n        System.out.print(\"Queue is Empty\");\r\n        return;\r\n    }\r\n\r\n\r\n    System.out.print(\"Elements in the \" +\r\n                    \"circular queue are: \");\r\n\r\n    if(rear &gt;= front)\r\n    {\r\n    \r\n        for(int i = front; i &lt;= rear; i++)\r\n        {\r\n            System.out.print(queue.get(i));\r\n            System.out.print(\" \");\r\n        }\r\n        System.out.println();\r\n    }\r\n\r\n    else\r\n    {\r\n        \r\n        for(int i = front; i &lt; size; i++)\r\n        {\r\n            System.out.print(queue.get(i));\r\n            System.out.print(\" \");\r\n        }\r\n\r\n        for(int i = 0; i &lt;= rear; i++)\r\n        {\r\n            System.out.print(queue.get(i));\r\n            System.out.print(\" \");\r\n        }\r\n        System.out.println();\r\n    }\r\n}\r\n\r\npublic static void main(String[] args)\r\n{\r\n\r\n    CircularQueue q = new CircularQueue(5);\r\n    \r\n    q.enQueue(14);\r\n    q.enQueue(22);\r\n    q.enQueue(13);\r\n    q.enQueue(-6);\r\n    \r\n    q.displayQueue();\r\n\r\n    int x = q.deQueue();\r\n\r\n    if(x != -1)\r\n    {\r\n        System.out.print(\"Deleted value = \");\r\n        System.out.println(x);\r\n    }\r\n\r\n    x = q.deQueue();\r\n\r\n    if(x != -1)\r\n    {\r\n        System.out.print(\"Deleted value = \");\r\n        System.out.println(x);\r\n    }\r\n\r\n    q.displayQueue();\r\n    \r\n    q.enQueue(9);\r\n    q.enQueue(20);\r\n    q.enQueue(5);\r\n    \r\n    q.displayQueue();\r\n    \r\n    q.enQueue(20);\r\n}\r\n}\r\n<\/pre>\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_12145_3\">\r\n\t\t\t\t\t\t\t\t<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">class CircularQueue():\r\n\r\n    # constructor\r\n    def __init__(self, size):\r\n        self.size = size\r\n        \r\n        self.queue = [None for i in range(size)]\r\n        self.front = self.rear = -1\r\n\r\n    def enqueue(self, data):\r\n        \r\n        if ((self.rear + 1) % self.size == self.front):\r\n            print(\" Queue is Full&#92;n\")\r\n            \r\n\r\n        elif (self.front == -1):\r\n            self.front = 0\r\n            self.rear = 0\r\n            self.queue[self.rear] = data\r\n        else:\r\n            \r\n        \r\n            self.rear = (self.rear + 1) % self.size\r\n            self.queue[self.rear] = data\r\n            \r\n    def dequeue(self):\r\n        if (self.front == -1): # condition for empty queue\r\n            print (\"Queue is Empty&#92;n\")\r\n            \r\n\r\n        elif (self.front == self.rear):\r\n            temp=self.queue[self.front]\r\n            self.front = -1\r\n            self.rear = -1\r\n            return temp\r\n        else:\r\n            temp = self.queue[self.front]\r\n            self.front = (self.front + 1) % self.size\r\n            return temp\r\n\r\n    def display(self):\r\n    \r\n\r\n        if(self.front == -1):\r\n            print (\"Queue is Empty\")\r\n\r\n        elif (self.rear &gt;= self.front):\r\n            print(\"Elements in the circular queue are:\",\r\n                                            end = \" \")\r\n            for i in range(self.front, self.rear + 1):\r\n                print(self.queue[i], end = \" \")\r\n            print ()\r\n\r\n        else:\r\n            print (\"Elements in Circular Queue are:\",\r\n                                        end = \" \")\r\n            for i in range(self.front, self.size):\r\n                print(self.queue[i], end = \" \")\r\n            for i in range(0, self.rear + 1):\r\n                print(self.queue[i], end = \" \")\r\n            print ()\r\n\r\n        if ((self.rear + 1) % self.size == self.front):\r\n            print(\"Queue is Full\")\r\n\r\nob = CircularQueue(5)\r\nob.enqueue(14)\r\nob.enqueue(22)\r\nob.enqueue(13)\r\nob.enqueue(-6)\r\nob.display()\r\nprint (\"Deleted value = \", ob.dequeue())\r\nprint (\"Deleted value = \", ob.dequeue())\r\nob.display()\r\nob.enqueue(9)\r\nob.enqueue(20)\r\nob.enqueue(5)\r\nob.display()\r\n<\/pre>\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_12145 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_12145 a\"),jQuery(\"#tab-content_12145\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<p><strong>Time complexity: O(1)<\/strong><\/p>\n<h2>Implementation of Circular Queue using Linked List<\/h2>\n<p>The address part of a linked list, a linear data structure that stores two parts\u2014the data part and the address part\u2014contains the node&#8217;s address is a linear data structure that stores two parts\u2014the data part and the address part\u2014contains the address of the node after it. Since the circular queue in this case is implemented using a linked list, the linked list complies with the Queue&#8217;s rules. Enqueue and dequeue operations take O(1) time when we implement a circular queue using a linked list.<\/p>\n<p><strong>Code Implementation:<\/strong><\/p>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_12147 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_12147 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_12147 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_12147 .wpsm_nav-tabs > li.active > a, #tab_container_12147 .wpsm_nav-tabs > li.active > a:hover, #tab_container_12147 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_12147 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_12147 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_12147 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_12147 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_12147 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_12147 .wpsm_nav-tabs > li > a:hover , #tab_container_12147 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_12147 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_12147 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_12147 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_12147 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_12147 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_12147 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_12147 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_12147 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_12147 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_12147 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_12147 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_12147\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_12147\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_12147_1\" aria-controls=\"tabs_desc_12147_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_12147\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_12147_1\">\r\n\t\t\t\t\t\t\t\t<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\">#include &lt;stdio.h&gt;  \r\n\/\/ Declaration of struct type node  \r\nstruct node  \r\n{  \r\n    int data;  \r\n    struct node *next;  \r\n};  \r\nstruct node *front=-1;  \r\nstruct node *rear=-1;  \r\n\/\/ function to insert the element in the Queue  \r\nvoid enqueue(int x)  \r\n{  \r\n    struct node *newnode;  \/\/ declaration of pointer of struct node type.  \r\n    newnode=(struct node *)malloc(sizeof(struct node));  \/\/ allocating the memory to the newnode  \r\n    newnode-&gt;data=x;  \r\n    newnode-&gt;next=0;  \r\n    if(rear==-1)  \/\/ checking whether the Queue is empty or not.  \r\n    {  \r\n        front=rear=newnode;  \r\n        rear-&gt;next=front;  \r\n    }  \r\n    else  \r\n    {  \r\n        rear-&gt;next=newnode;  \r\n        rear=newnode;  \r\n        rear-&gt;next=front;  \r\n    }  \r\n}  \r\n  \r\n\/\/ function to delete the element from the queue  \r\nvoid dequeue()  \r\n{  \r\n    struct node *temp;   \/\/ declaration of pointer of node type  \r\n    temp=front;  \r\n    if((front==-1)&amp;&amp;(rear==-1))  \/\/ checking whether the queue is empty or not  \r\n    {  \r\n        printf(\"&#92;nQueue is empty\");  \r\n    }  \r\n    else if(front==rear)  \/\/ checking whether the single element is left in the queue  \r\n    {  \r\n        front=rear=-1;  \r\n        free(temp);  \r\n    }  \r\n    else  \r\n    {  \r\n        front=front-&gt;next;  \r\n        rear-&gt;next=front;  \r\n        free(temp);  \r\n    }  \r\n}  \r\n  \r\n\/\/ function to get the front of the queue  \r\nint peek()  \r\n{  \r\n    if((front==-1) &amp;&amp;(rear==-1))  \r\n    {  \r\n        printf(\"&#92;nQueue is empty\");  \r\n    }  \r\n    else  \r\n    {  \r\n        printf(\"&#92;nThe front element is %d\", front-&gt;data);  \r\n    }  \r\n}  \r\n  \r\n\/\/ function to display all the elements of the queue  \r\nvoid display()  \r\n{  \r\n    struct node *temp;  \r\n    temp=front;  \r\n    printf(\"&#92;n The elements in a Queue are : \");  \r\n    if((front==-1) &amp;&amp; (rear==-1))  \r\n    {  \r\n        printf(\"Queue is empty\");  \r\n    }  \r\n  \r\n    else   \r\n    {  \r\n        while(temp-&gt;next!=front)  \r\n        {  \r\n            printf(\"%d,\", temp-&gt;data);  \r\n            temp=temp-&gt;next;  \r\n        }  \r\n        printf(\"%d\", temp-&gt;data);  \r\n    }  \r\n}  \r\n  \r\nvoid main()  \r\n{  \r\n    enqueue(34);   \r\n    enqueue(10);  \r\n    enqueue(23);  \r\n    display();   \r\n    dequeue();   \r\n    peek();  \r\n}<\/pre>\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_12147 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_12147 a\"),jQuery(\"#tab-content_12147\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<h2>Applications of Circular Queue in Data Structure<\/h2>\n<p>The circular Queue in data structure can be used in the following scenarios:<\/p>\n<ul>\n<li><strong>Memory Management:<\/strong> Memory management is provided by the circular queue. As we&#8217;ve just shown, memory is not managed particularly effectively in a linear queue. However, in the case of a circular queue, the memory is effectively managed by putting the elements in an empty space.<\/li>\n<li><strong>CPU Scheduling:<\/strong> The circular queue in data structure is another tool the operating system employs to insert and then run programs.<\/li>\n<li><strong>Traffic System:<\/strong> One of the best instances of a circular queue in a traffic management system controlled by computers is a traffic signal. After each interval of time, each traffic light turns on one at a time. Like when a red light comes on for a minute, followed by a yellow light for a minute, and then a green light. The red light turns on after the green light. <\/li>\n<\/ul>\n<p><strong>Conclusion<\/strong><br \/>\nIn conclusion, understanding the circular queue in data structures is essential for efficiently managing data and processes that exhibit cyclic behavior. Circular queues combine the properties of both queues and circular structures, offering advantages in resource allocation, buffering, scheduling, and various other applications. Their ability to handle elements in a cyclic manner while maintaining efficient memory utilization makes them a valuable tool in various domains of computer science and engineering.<\/p>\n<h2>Frequently Asked Questions (FAQs) about Circular Queue in Data Structure:<\/h2>\n<p>Below are the FAQs related to Circular Queue in Data Structure:<\/p>\n<p><strong>1. What is the advantage of using a circular queue?<\/strong><br \/>\nCircular queues efficiently manage cyclic data or processes and utilize memory effectively by reusing available space.<\/p>\n<p><strong>2. How is a circular queue implemented?<\/strong><br \/>\nA circular queue can be implemented using arrays or linked lists. In arrays, modulo arithmetic is used to wrap around the queue, while linked lists are modified to form a circular arrangement.<\/p>\n<p><strong>3. What is the significance of circular increment in a circular queue?<\/strong><br \/>\nCircular increment ensures that when the end of the queue is reached, the next element is positioned at the beginning of the queue, forming a circular structure.<\/p>\n<p><strong>4. What are the main operations supported by a circular queue?<\/strong><br \/>\nThe primary operations of a circular queue include enqueue (addition of an element), dequeue (removal of an element), front (retrieve the front element), rear (retrieve the rear element), and isEmpty (check if the queue is empty).<\/p>\n<p><strong>5. What are the applications of circular queues in data structures?<\/strong><br \/>\nCircular queues are used in resource allocation, buffering, scheduling, simulation systems, data transmission, print spooling, real-time systems, networking, memory management, and more.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this Blog, we will talk about circular queue in data structure. We will cover the multiple approaches to implement circular queue in data structure. Also we will see the applications of circular queue in data structure. Circular queue is an efficient data structure in comparison with a simple queue as it doesn&#8217;t waste the [&hellip;]<\/p>\n","protected":false},"author":52,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[128],"tags":[40,149],"class_list":["post-8762","post","type-post","status-publish","format-standard","hentry","category-queues","tag-array","tag-queue"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Circular Queue in Data Structure<\/title>\n<meta name=\"description\" content=\"Circular queue is a linear data structure which follows the FIFO(First in first out) property. In this article, we&#039;ll implement circular queue using array.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/prepbytes.com\/blog\/circular-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=\"Circular Queue in Data Structure\" \/>\n<meta property=\"og:description\" content=\"Circular queue is a linear data structure which follows the FIFO(First in first out) property. In this article, we&#039;ll implement circular queue using array.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/circular-queue-in-data-structure\/\" \/>\n<meta property=\"og:site_name\" content=\"PrepBytes Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prepbytes0211\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-06-29T11:50:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-09-22T10:28:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1674633612908-Circular%20Queue%20in%20Data%20Structure.jpg\" \/>\n<meta name=\"author\" content=\"Prepbytes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prepbytes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/circular-queue-in-data-structure\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/circular-queue-in-data-structure\/\"},\"author\":{\"name\":\"Prepbytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\"},\"headline\":\"Circular Queue in Data Structure\",\"datePublished\":\"2022-06-29T11:50:30+00:00\",\"dateModified\":\"2023-09-22T10:28:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/circular-queue-in-data-structure\/\"},\"wordCount\":984,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/circular-queue-in-data-structure\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1674633612908-Circular%20Queue%20in%20Data%20Structure.jpg\",\"keywords\":[\"array\",\"queue\"],\"articleSection\":[\"Queues\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/circular-queue-in-data-structure\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/circular-queue-in-data-structure\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/circular-queue-in-data-structure\/\",\"name\":\"Circular Queue in Data Structure\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/circular-queue-in-data-structure\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/circular-queue-in-data-structure\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1674633612908-Circular%20Queue%20in%20Data%20Structure.jpg\",\"datePublished\":\"2022-06-29T11:50:30+00:00\",\"dateModified\":\"2023-09-22T10:28:26+00:00\",\"description\":\"Circular queue is a linear data structure which follows the FIFO(First in first out) property. In this article, we'll implement circular queue using array.\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/circular-queue-in-data-structure\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/circular-queue-in-data-structure\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/circular-queue-in-data-structure\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1674633612908-Circular%20Queue%20in%20Data%20Structure.jpg\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1674633612908-Circular%20Queue%20in%20Data%20Structure.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/circular-queue-in-data-structure\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/43.205.93.38\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Queues\",\"item\":\"https:\/\/prepbytes.com\/blog\/category\/queues\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Circular Queue in Data Structure\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/43.205.93.38\/#website\",\"url\":\"http:\/\/43.205.93.38\/\",\"name\":\"PrepBytes Blog\",\"description\":\"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING\",\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/43.205.93.38\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/43.205.93.38\/#organization\",\"name\":\"Prepbytes\",\"url\":\"http:\/\/43.205.93.38\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"contentUrl\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"width\":160,\"height\":160,\"caption\":\"Prepbytes\"},\"image\":{\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/prepbytes0211\/\",\"https:\/\/www.instagram.com\/prepbytes\/\",\"https:\/\/www.linkedin.com\/company\/prepbytes\/\",\"https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA\"]},{\"@type\":\"Person\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\",\"name\":\"Prepbytes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"caption\":\"Prepbytes\"},\"url\":\"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Circular Queue in Data Structure","description":"Circular queue is a linear data structure which follows the FIFO(First in first out) property. In this article, we'll implement circular queue using array.","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:\/\/prepbytes.com\/blog\/circular-queue-in-data-structure\/","og_locale":"en_US","og_type":"article","og_title":"Circular Queue in Data Structure","og_description":"Circular queue is a linear data structure which follows the FIFO(First in first out) property. In this article, we'll implement circular queue using array.","og_url":"https:\/\/prepbytes.com\/blog\/circular-queue-in-data-structure\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2022-06-29T11:50:30+00:00","article_modified_time":"2023-09-22T10:28:26+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1674633612908-Circular%20Queue%20in%20Data%20Structure.jpg","type":"","width":"","height":""}],"author":"Prepbytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Prepbytes","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/circular-queue-in-data-structure\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/circular-queue-in-data-structure\/"},"author":{"name":"Prepbytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e"},"headline":"Circular Queue in Data Structure","datePublished":"2022-06-29T11:50:30+00:00","dateModified":"2023-09-22T10:28:26+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/circular-queue-in-data-structure\/"},"wordCount":984,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/circular-queue-in-data-structure\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1674633612908-Circular%20Queue%20in%20Data%20Structure.jpg","keywords":["array","queue"],"articleSection":["Queues"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/circular-queue-in-data-structure\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/circular-queue-in-data-structure\/","url":"https:\/\/prepbytes.com\/blog\/circular-queue-in-data-structure\/","name":"Circular Queue in Data Structure","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/circular-queue-in-data-structure\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/circular-queue-in-data-structure\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1674633612908-Circular%20Queue%20in%20Data%20Structure.jpg","datePublished":"2022-06-29T11:50:30+00:00","dateModified":"2023-09-22T10:28:26+00:00","description":"Circular queue is a linear data structure which follows the FIFO(First in first out) property. In this article, we'll implement circular queue using array.","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/circular-queue-in-data-structure\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/circular-queue-in-data-structure\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/circular-queue-in-data-structure\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1674633612908-Circular%20Queue%20in%20Data%20Structure.jpg","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1674633612908-Circular%20Queue%20in%20Data%20Structure.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/circular-queue-in-data-structure\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/43.205.93.38\/"},{"@type":"ListItem","position":2,"name":"Queues","item":"https:\/\/prepbytes.com\/blog\/category\/queues\/"},{"@type":"ListItem","position":3,"name":"Circular Queue in Data Structure"}]},{"@type":"WebSite","@id":"http:\/\/43.205.93.38\/#website","url":"http:\/\/43.205.93.38\/","name":"PrepBytes Blog","description":"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING","publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/43.205.93.38\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/43.205.93.38\/#organization","name":"Prepbytes","url":"http:\/\/43.205.93.38\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/","url":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","contentUrl":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","width":160,"height":160,"caption":"Prepbytes"},"image":{"@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/prepbytes0211\/","https:\/\/www.instagram.com\/prepbytes\/","https:\/\/www.linkedin.com\/company\/prepbytes\/","https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA"]},{"@type":"Person","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e","name":"Prepbytes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","caption":"Prepbytes"},"url":"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/"}]}},"_links":{"self":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/8762","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/users\/52"}],"replies":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/comments?post=8762"}],"version-history":[{"count":7,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/8762\/revisions"}],"predecessor-version":[{"id":18014,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/8762\/revisions\/18014"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=8762"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=8762"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=8762"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}