链表注意事项

1.问题:把旧链表的结点依次按顺序放入新链表。

设置两个相邻p,q  防止丢失原链表next信息


    struct node *p, *q;
    p=head->next;
    head->next=NULL;
    q=p->next;
    while(p)
    {
        p->next=head->next;
        head->next=p;
        //对p进行操作后该结点位置变化
        p=q;
        if(q) q=q->next;
    }

猜你喜欢

转载自blog.csdn.net/weixin_44153125/article/details/88931856