剑指offer 面试题13 在O(1)时间删除给定结点

来源:互联网 发布:东非大裂谷 知乎 编辑:程序博客网 时间:2024/05/17 22:48


struct ListNode{int data;ListNode* next;}; void DeleteNode(ListNode** pHead,ListNode* Del){if(*pHead==NULL||Del==NULL) return;//异常处理 if(Del->next!=NULL){ListNode* pDel==NULL;pDel=Del->next;Del->data=pDel->data;Del->next=pDel->next;delete pDel;pDel==NULL;//置空指针 }else if(*pHead==Del){*pHead==NULL;delete Del;Del=NULL;//置空指针 }else{ListNode *pNode==*pHead;while(pNode->next!=Del){pNode==pNode->next;}pNode->next=NULL;delete Del;Del=NULL;//置空指针}}


0 0
原创粉丝点击