Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update list_queue_dequeue function #525

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 27 additions & 24 deletions c-cpp/09_queue/list_queue/list_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,32 @@ list_queue *list_queue_create()

return queue;
}

/*出队*/
int list_queue_dequeue(list_queue *queue,int *data)
{
queue_node * ptmp = NULL;

if ((queue == NULL) || (data == NULL) || list_queue_is_empty(queue))
{
return -1;
}

*data = queue->head->data;
ptmp = queue->head;
queue->head = queue->head->next;
queue->num--;

if (queue->head == NULL)
{
queue->tail = NULL;
}


free(ptmp);
return 0;
}

void list_queue_destroy(list_queue*queue)
{
int i = 0;
Expand All @@ -39,6 +65,7 @@ void list_queue_destroy(list_queue*queue)

while(!list_queue_is_empty(queue))
{
/*因为这里需要用到出队函数,所以应当在使用前声明或定义出队函数*/
(void)list_queue_dequeue(queue,&data);
}

Expand Down Expand Up @@ -77,30 +104,6 @@ int list_queue_enqueue(list_queue *queue,int data)
return 0;
}

/*出队*/
int list_queue_dequeue(list_queue *queue,int *data)
{
queue_node * ptmp = NULL;

if ((queue == NULL) || (data == NULL) || list_queue_is_empty(queue))
{
return -1;
}

*data = queue->head->data;
ptmp = queue->head;
queue->head = queue->head->next;
queue->num--;

if (queue->head == NULL)
{
queue->tail = NULL;
}


free(ptmp);
return 0;
}
void list_queue_dump(list_queue*queue)
{
int i = 0;
Expand Down