I'm trying to get my dequeue method working on my implementation of a LinkedList ADT. However, it is removing from the beginning of the queue instead of the end. Any help with this? I'm new to C, and am trying to port a java exercise over to C.. It's supposed to remove the last node of the list.
Here's my dequeue method:
static void linkedQueueDequeue(Queue* q) {
LinkedQueue *lq = ((LinkedQueue*)q->privateData);
Node* temp = lq->head->next;
lq->head->data = lq->head->next->data;
lq->head->next = temp->next;
free(temp);
lq->size--;
}
Here's the output when trying to dequeue last node:
=====================
|Testing LinkedQueue|
=====================
adding 1 to first node
adding 2 to second node
adding 3 to third node
adding 4 to fourth node
[1,2,3,4]
dequeue last node
should print [1,2,3]
[2,3,4]
return first node
peek: 2
what's the size?
size: 3