Skip to main content
Engineering LibreTexts

10.2: Looking at the queue code

  • Page ID
    34688
  • We have already learned how to use linked lists, and how to use that concept in creating and managing a Stack. So, we wil take a look at the code for a Queue.

    struct QNode { 
    int data;
    QNode* next;
    };

    This piece should look familiar. In the linked list we called it a Node,  in the stack the example code called it a StackNode. It is simply a structure that contains our data and a pointer to the next item in the list/stack/queue. 

    Also - understand that the struct can contain multiple data types, it is not restricted to a single int. For example:

    struct QNode { 
    int data;
    string fName;
    string lName;
    float cost;
    QNode* next;
    };

    When we use these data types we manage the first, next and last points (and any other pointers we need to manage). 

    Adapted from: "Queue – Linked List Implementation" by Gaurav Kumar is licensed under CC BY-SA 4.0

    • Was this article helpful?