Frage

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?

War es hilfreich?

Lösung

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 ++;
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top