核心代码如下:
//删除pos位置的节点
int DeletePosList(Node *pHead,Node *pTail,int pos){
int i = 1;
Node *pMove;
pMove = pHead->next;
while (pMove != pTail) {
if (i == pos) {
pMove->prior->next = pMove->next;
pMove->next->prior = pMove->prior;
free(pMove);
pMove = NULL;
printf("%s函数执行,删除pos=%d位置的节点成功\n",__FUNCTION__,pos);
return 1;
}
i++;
pMove = pMove->next;
}
printf("%s函数执行,删除pos=%d位置的节点失败\n",__FUNCTION__,pos);
return 0;
}
//删除值为x的节点,若存在该节点则删除之
int DeleteValueList(Node *pHead,Node *pTail,int x){
Node *pMove;
pMove = pHead->next;
while (pMove != pTail) {
if (pMove->element == x) {
pMove->prior->next = pMove->next;
pMove->next->prior = pMove->prior;
free(pMove);
pMove = NULL;
printf("%s函数执行,删除值为x=%d的节点成功\n",__FUNCTION__,x);
return 1;
}
pMove = pMove->next;
}
printf("%s函数执行,删除值为x的节点失败\n",__FUNCTION__);
return 0;
}