A function in C to `push` items to a queue -
using c write push(queue **, nod *)
method. want check if have covered basics when pushing nods
onto queue
.
void push_back(queue ** q, process * p){ p->next = null; if( (*q)->head == null && (*q)->tail ==null){ (*q)->head = (*q)->tail = p; } (*q)->tail->next = p->next; (*q)->tail = p; }
am assigning null
(*q)->tail->next
assigning p->next
correctly?
(*q)->tail->next
should null
.
and if queue not empty don't link in new node properly. instead if queue not empty should make (*q)->tail->next
point p
, make tail point p
:
if (/* queue empty */) { ... } else { (*q)->tail->next = p; (*q)->tail = p; }
and said in comments, don't seem need indirection created passing pointer pointer, mean rewrite (with changes) as
void push_back(queue * q, process * p){ p->next = null; if( q->head == null && q->tail ==null){ q->head = q->tail = p; } else { q->tail->next = p; q->tail = p; } }
Comments
Post a Comment