C programming removing from queue using FIFO (first in first out) -
i have been tasked writing functions add together of queue , remove front.
i have wrote function add together queue:
void queue_put(queue *q, qitem *new_item) { new_item->next = null; if (queue_empty(q)){ q->front = new_item; } else { q->back->next = new_item; } q->back = new_item; }
this works fine i'm struggling write function removes front end of queue:
qitem * queue_get(queue *q) { if (queue_empty(q)) { homecoming (qitem *)0; } else { qitem front_item = q->front; q->front = q->front->next; homecoming front_item; } }
above best effort doesn't work , i'm wondering if can help? realize basic issue i'm quite new this.
what one?
qitem * queue_get(queue *q) { if (queue_empty(q)) { homecoming (qitem *)0; } else { qitem *front_item = q->front; qitem *back_item = q->back; q->front = q->front->next; if (front_item == back_item) { q->back = null; // single element } homecoming front_item; } }
c queue
No comments:
Post a Comment