How to remove items from a single list?

struct QUEUE
{
 NODE* info;
 QUEUE *next;
};
NODE* take_out(QUEUE *q, int *error)
{
 QUEUE *old_item = q; // beginning of queue
 NODE *old_info = 0;
 if (q) // if the queue is not empty
{
 old_info = old_item->info;
 q = (q)->next;
 delete old_item; // destruction of the item
 *error = 0;
}
 else *error = 1;
 return old_info;
}
void prefix(NODE *p)
{
 int *err=new int;
 QUEUE *queue = 0;
 while (p != 0 || !isempty(queue)){
 if (!isempty(queue))
{
 p = take_out(queue, err);
}

 while (p != 0){
 printf(" %-7d ", p->info);
 if (p->right != 0) 
queue=append(queue,p->right);
 p = p->left;
}
}
}

How to make to function take_out freed memory queue? now it is not working properly and therefore the isempty function indicates that the queue is not empty while all the elements are removed. They are designated as ???.
July 2nd 19 at 17:58
1 answer
July 2nd 19 at 18:00
After calling the take_out (usually called pop), which shows the head of the queue? Variable queue points to the address which has just been released.

in take_out either return a pointer to the new head:
QUEUE* take_out(QUEUE *q, NODE *node, int *error)
{
 QUEUE *old_item = q; // beginning of queue
 NODE *old_info = 0;
 if (q) // if the queue is not empty
{
 old_info = old_item->info;
 q = (q)->next;
 delete old_item; // destruction of the item
 *error = 0;
}
 else *error = 1;

 node = old_info;

 return q;


....
 queue = take_out(queue, p, err)
}

or do a queue like
struct List;

struct List
{
 struct List *next;
 NODE *info;
};

typedef struct
{
 struct List *head;
} QUEUE;

int pop(QUEUE* q, NODE* info)
{
 int ret;

 if (q && q->head)
{
 info = q->head->info;
 q->head = q->head->next;
 ret = 0;
}
else
{
 ret = -1;
}
}


for me, the second option is better.

Find more questions by tags CC++ProgrammingData structuresMessage queues