Inserting an element into the Queue ADT

Inserting a new item in the Queue data type can only be performed from the back side, which means the newly inserted item will be pointed by the m_back pointer, and the Next pointer of the current element will point to this new element to create a new chaining node. However, it can be applied if there's at least one element before we insert the new element. If Queue is empty when we are going to insert a new element, we have to set the new element to be the front and the back element. Let's explore the following Enqueue() operation's implementation:

template <typename T>void Queue<T>::Enqueue(T val){    // Create a new Node    Node<T> * node = new Node<T>(val);    if(m_count == 0)    { // If the queue is empty ...

Get C++ Data Structures and Algorithms now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.