链接列表,在前面插入一个节点

时间:2013-02-17 14:09:12

标签: c linked-list

给定一个包含链表的对象,当我无法返回该链表的内存地址时,如何将新节点添加到该链表的头部?

struct group {
    char *name;
    struct user *users;
    struct xct *xcts;
    struct group *next;
};

struct user {
    char *name;
    double balance;
    struct user *next;
};

1 个答案:

答案 0 :(得分:4)

这比你想象的要简单得多:

usr->next = group->users;
group->users = usr;