Skip to main content
Engineering LibreTexts

10.6: Circular queue

  • Page ID
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Operations on Circular Queue:

    • qInsert(value) This function is used to insert an element into the circular queue. In a circular queue, the new element is always inserted at Rear position.Steps:
      1. Create a new node dynamically and insert value into it.
      2. Check if front==NULL, if it is true then front = rear = (newly created node)
      3. If it is false then rear=(newly created node) and rear node always contains the address of the front node.
    • qRemove() This function is used to delete an element from the circular queue. In a queue, the element is always deleted from front position.Steps:
      1. Check whether queue is empty or not means front == NULL.
      2. If it is empty then display Queue is empty. If queue is not empty then step 3
      3. Check if (front==rear) if it is true then set front = rear = NULL else move the front forward in queue, update address of front in rear node and return the element.

    Here is an example of inserting and removing a few values with a circular queue

    Examples of operations on a circular Queue - "Circular Queue | Set 2 (Circular Linked List Implementation)" by andrew1234, Geeks for Geeks is licensed under CC BY-SA 4.0

    This is the same as the non-circular EXCEPT that you must update the rear->next value to point to the head when you qRemove(), and set the new rear->next when you qInsert().

    "Circular Queue | Set 2 (Circular Linked List Implementation)" by Arnab Kundu is licensed under CC BY-SA 4.0

    This page titled 10.6: Circular queue is shared under a CC BY-SA license and was authored, remixed, and/or curated by Patrick McClanahan.

    • Was this article helpful?