From afd8cc01a5d5e6b3b11e2db12d3b1fb39c252cf3 Mon Sep 17 00:00:00 2001 From: MapleSign <347495867@qq.com> Date: Thu, 8 Feb 2018 11:23:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=90=9E=E5=AE=9A=E4=BA=86remove=E5=92=8Cpop?= =?UTF-8?q?=EF=BC=8C=E4=BD=86=E6=98=AF=E4=BC=9A=E5=87=BA=E7=8E=B0=E5=86=85?= =?UTF-8?q?=E5=AD=98=E6=B3=84=E6=BC=8F=E7=9A=84=E6=83=85=E5=86=B5=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list/list.h | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/list/list.h b/list/list.h index 9b069db..f8b35a8 100644 --- a/list/list.h +++ b/list/list.h @@ -39,3 +39,69 @@ int insertInTail(List *p_list, Node *p_node){ p_list->tail = p_node; return 0; } + +int removeById(List *p_list, unsigned long id){ + Node *tmp = p_list->head; + if(tmp == NULL) + return -1;//这说明p_list指向空列表 + + do{ + if( *(tmp->value) == id ){ + tmp->last->next = tmp->next; + tmp->next->last = tmp->last; + return 1;//找到了 + } + else + tmp = tmp->next; + }while(tmp != NULL) + + return 0;//没找到 +} + +int removeByNode(List *p_list, Node *p_node){ + Node *tmp = p_list->head; + if(tmp == NULL) + return -1;//这说明p_list指向空列表 + + do{ + if(tmp == p_node){ + tmp->last->next = tmp->next; + tmp->next->last = tmp->last; + return 1;//找到了 + } + else + tmp = tmp->next; + }while(tmp != NULL) + + return 0;//没找到 +} + +int popFromHead(List *p_list){ + if(p_list->head == NULL) + return -1; + + if(p_list->head->next == NULL){ + p_list->head = NULL; + p_list->tail = NULL; + } + else{ + p_list->head->next->last = NULL; + p_list->head = p_list->head->next; + } + return 0; +} + +int popFromTail(List *p_list){ + if(p_list->head == NULL) + return -1; + + if(p_list->head->next == NULL){ + p_list->head = NULL; + p_list->tail = NULL; + } + else{ + p_list->tail->last->next = NULL; + p_list->tail = p_list->tail->last; + } + return 0; +}