1 #include "stdafx.h" 2 #include <iostream> 3 #include <exception> 4 using namespace std; 5 6 struct ListNode 7 { 8 int m_nValue; 9 ListNode* m_pnext; 10 }; 11 12 void InsertNodeTail(ListNode** L,int num) 13 { 14 ListNode* node = new ListNode(); 15 node->m_nValue = num; 16 node->m_pnext = NULL; 17 if(*L == NULL) 18 { 19 *L = node; 20 } 21 else 22 { 23 ListNode *pHead=*L; 24 while(pHead->m_pnext!=NULL) 25 pHead=pHead->m_pnext; 26 pHead->m_pnext = node; 27 } 28 } 29 30 void RemoveNode(ListNode** pHead,int value) 31 { 32 if(pHead ==NULL||*pHead ==NULL) 33 return; 34 ListNode* pToBeDeleted = NULL; 35 if((*pHead)->m_nValue == value) 36 { 37 pToBeDeleted = *pHead; 38 *pHead = (*pHead)->m_pnext; 39 } 40 else 41 { 42 ListNode* pNode = *pHead; 43 while(pNode->m_pnext != NULL && pNode->m_pnext->m_nValue!=value) 44 pNode = pNode ->m_pnext; 45 if(pNode->m_pnext != NULL && pNode ->m_pnext->m_nValue ==value) 46 { 47 pToBeDeleted = pNode->m_pnext; 48 pNode->m_pnext = pNode->m_pnext->m_pnext; 49 } 50 } 51 if(pToBeDeleted!=NULL){ 52 delete pToBeDeleted; 53 pToBeDeleted = NULL; 54 } 55 56 } 57 int _tmain(int argc, _TCHAR* argv[]) 58 { 59 60 return 0 ; 61 }