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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

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

android - How to create dynamically Fragment pager adapter -