如何在链表的开头插入节点?

use*_*625 0 c linked-list data-structures

有什么问题addAtBegin?该列表似乎是将新创建正确的后nodestart,但何时控制返回main,新的值不会被保存.

typedef struct node
{
    int data;
    struct node *link;
}node;

node* createList(int data)
{
    node *tempNode=(node*)malloc(sizeof(node));
    tempNode->data=data;
    tempNode->link=NULL;
    return tempNode;
}

void addAtBegin(node *start,int data)
{
    node *addedNode=(node *)malloc(sizeof(node));
    addedNode->data=data;
    addedNode->link=(start==NULL)?NULL:start;
    start=addedNode;
}

void displayNodes(node *start)
{
    node *startCopy=start;
    while(startCopy!=NULL)
    {
        printf("%d\t",startCopy->data);
        startCopy=startCopy->link;
    }
    printf("\n");
}

int main( )
{   
    node *start=createList(2);
    addAtBegin(start,1);
    displayNodes(start);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

小智 5

看起来像我的另一个列表问题,与大多数问题的答案相同 - start应该是指向指针的指针.