Skip to main content
Engineering LibreTexts

10.1: Queues

  • Page ID
    34687
  • \( \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}}\)

    Like Stack, Queue is a linear structure which follows a particular order in which the operations are performed. The order is First IFirst Out (FIFO).  A good example of queue is any queue of consumers for a resource where the consumer that came first is served first.


    The difference between stacks and queues is in removing. In a stack we remove the item the most recently added; in a queue, we remove the item the oldest item on the queue.

    Operations on Queue:
    Mainly the following two basic operations are performed on queue:

    Enqueue: Adds an item to the queue. If the queue is full, then it is said to be an Overflow condition.
    Dequeue: Removes an item from the queue. The items are popped in the same order in which they are pushed. If the queue is empty, then it is said to be an Underflow condition.

    Some Queue implementations also provide two additional operations:
    Front: Get the front item from queue.
    Rear: Get the last item from queue.

     

    Picture showing Front of the Queue, where things are removed, and Rear of the Queue where things are added to the queue

    Notice that they refer to the "rear" of the queue as where we add new items. The "front" is where we pull things off of the queue. This may seem a bit backwards, so make sure you have your terminology correct.

    "Queue | Set 1 (Introduction and Array Implementation)" by Soumik Mondal is licensed under CC BY-SA 4.0


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

    • Was this article helpful?