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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -