Skip to main content
Engineering LibreTexts

10.3: Looking at the queue code (continued)

  • Page ID
    34689
  • Let's take a quick look at the class we are going to define, and the constructor:

    struct Queue { 
     QNode *front, *rear;

       Queue()
     {
          front = rear = NULL;
       }

    We want to keep track of the front of the queue - which is where we take things off of the queue, and we want to keep track of the rear of the queue, where we put things onto the queue. Remember, the default is that these pointers are private.

    The constructor simply sets both the front and the rear pointers to NULL. So, when we declare an instance of this class in our code:

    int main() 
    {
    Queue q;
    the pointers are set to Null, as we have not yet allocated any memory for them.
    Adapted from: "Queue – Linked List Implementation" by Gaurav Kumar is licensed under CC BY-SA 4.0
    • Was this article helpful?