Question

For a project, I want to insert ASCII letters at the end of queue and numbers at the front of queue. I know how to insert things at the end of the queue, but I am stuck on the latter.

Here is my enqueue function:

void LinkedQueue::enqueue(ElementType new_data)
{
    Node *newNode = new Node(new_data);
    Node *tempholder = head;
    while (tempholder->next !=NULL)
    {
        tempholder = tempholder->next;
    }
    tempholder->next = newNode;
    mySize ++;
}

How would I modify this for another function named enqueue_front?

Was it helpful?

Solution

Simple Linked List modification does the trick.

void LinkedQueue::enqueue_front(ElementType new_data)
{
    Node *newNode = new Node(new_data);
    newNode->next = head;
    head = newNode;    
    mySize ++;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top