As mentionned in the comments:
- we have little understanding about what is guaranteed about
q
(or whatqNode
orQueue
look like) root
is allocated at the start of the function but the pointer value get replaced byq->front
, causing a memory leak, could probably be detected by your compiler by enabling warnings.- is
q
orq->front
notNULL
? - please check if
root
is notNULL
before checkingroot->next
- ending if
root->next
isNULL
would mean that the last node ( with content ) will be skipped because it does not have anext
( trace your algorithm by hand to verify )
suggested fixes (file output skipped for brevity):
void findFlight(Queue *q, int flightNum){
if( q == NULL ) return;
qNode *current = q->front;
if( current == NULL ) return;
while(current != NULL) {
if( current->flightNum == flightNum ) {
// we assume that current->fullName is actually set, but feel free to verify
fprintf(stdout, "%s is taking flight %d", current->fullName, current->flightNum);
}
current = current->next;
}
}