Reputation: 59
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
?
Upvotes: 1
Views: 3077
Reputation: 1263
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 ++;
}
Upvotes: 1