1 /**************************************** 2 > File Name:test.c 3 > Author:xiaoxiaohui 4 > mail:1924224891@qq.com 5 > Created Time:2016年05月26日 星期四 18时42分19秒 6 ****************************************/ 7 8 9 10 11 //一.即不是头节点也不是尾节点 12 //二.为头节点 13 //三.为尾节点 14 15 16 17 #include<stdio.h> 18 #include<assert.h> 19 20 21 void DeleteNode(ListNode** head, ListNode* node) 22 { 23 assert(head); 24 assert(node); 25 26 if(node->_next != NULL) //非尾节点 也肯定不是头节点 27 { 28 ListNode* pNext = node->_next; 29 node->_data = pNext->_data; 30 node->_next = pNext->_next; 31 32 delete pNext; 33 pNext = NULL; 34 } 35 else if(*head == node) //为头节点 36 { 37 delete node; 38 node = NULL; 39 *head = NULL; 40 } 41 else //尾节点 42 { 43 ListNode* tem = *head; 44 45 while(tem->_next != node) 46 { 47 tem = tem->_next; 48 } 49 50 tem-_next = NULL; 51 delete node; 52 node = NULL; 53 } 54 }
本文转自 ye小灰灰 51CTO博客,原文链接:http://blog.51cto.com/10704527/1783643,如需转载请自行联系原作者