1 void RemoveNode(ListNode** pHead,int value) 2 { 3 if(pHead==NULL||*pHead==NULL) 4 return; 5 ListNode* pToBeDeleted = NULL; 6 if((*pHead)->m_nValue==value) 7 { 8 pToBeDeleted=*pHead; 9 *pHead=(*pHead)->m_pNext; 10 } 11 else 12 { 13 ListNode* pNode= *pHead; 14 while(pNode->m_pNext!=NULL&&pNode->m_pNext->m_nValue!=value) 15 pNode=pNode->m_pNext; 16 if(pNode->m_pNext!=NULL&&pNode->m_pNext->m_nValue==value) 17 { 18 pToBeDeleted=pNode->m_pNext; 19 pNode->m_pNext=pNode->m_pNext->m_pNext; 20 21 } 22 } 23 if(pToBeDeleted!=NULL) 24 { 25 delete pToBeDeleted; 26 pToBeDeleted=NULL; 27 } 28 }