From d3550aa26b97d78e693e8474027ad3cfb8d8cc7a Mon Sep 17 00:00:00 2001 From: Saturneic Date: Sun, 10 Jun 2018 17:47:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list/list.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/list/list.h b/list/list.h index 9c74c6d..180081a 100644 --- a/list/list.h +++ b/list/list.h @@ -41,6 +41,9 @@ unsigned long long getId(void); int insertInHead(List *p_list, Node *p_node); int insertInTail(List *p_list, Node *p_node); +/*交换函数*/ +int exchangeLocation(Node *p_node,Node *t_node); + /*移除函数*/ int removeById(List *p_list, unsigned long id); int removeByNode(List *p_list, Node *p_node); @@ -467,4 +470,18 @@ int isListEmpty(List *p_list){ return 0; // want to make a list empty. } +int exchangeLocation(Node *p_node,Node *t_node){ + Node *temp_next = p_node->next; + Node *temp_last = p_node->last; + p_node->last->next = t_node; + p_node->next->last = t_node; + t_node->last->next = p_node; + t_node->next->last = p_node; + p_node->next = t_node->next; + p_node->last = t_node->last; + t_node->next = temp_next; + t_node->last = temp_last; + return 0; +} + #endif