如果想要删掉链表中所有值是x的节点怎么删 这样写的话只能删掉第一个


int DeleteNode(Node** phead, double x){
    Node *currNode = *phead;
    Node *prev = NULL;
    
    for(int pos = 1; currNode; prev = currNode, currNode=currNode->next){
        if(currNode->data == x){
            if(prev){
                prev->next = currNode->next;
            }
            else {
                *phead = currNode->next;
            }
            free(currNode);
            return pos;
        }
        pos++;
    }
    return 0;
}

你可以看我博客中的单链表操作,里面刚好有哦,还有其他复杂操作,希望对你有用。

你这个不是在删除第一个x的时候,就return了吗? return pos?