c - My dequeue function doesn't work properly, what is my mistake? -
struct node* dequeue(struct queue *queue) { struct node *temp = queue->front; if (temp == null) { printf("nothing delete"); return temp; } else if (temp->next == null) { free(temp); queue->front = null; queue->rear = null; printf("successfully delete."); return temp; } else { queue->rear = queue->rear->next; free(temp); printf("successfully delete."); return temp; } }
as printed in main() function data of deleted node, appears outputting random number, mistake here? please help.
you both free
, return
node. if want free node, don't return it. if want return node, don't free it. now, returning pointer node before freed it. use that?
Comments
Post a Comment