给定一个包含链表的对象,当我无法返回该链表的内存地址时,如何将新节点添加到该链表的头部?
struct group {
char *name;
struct user *users;
struct xct *xcts;
struct group *next;
};
struct user {
char *name;
double balance;
struct user *next;
};
答案 0 :(得分:4)
这比你想象的要简单得多:
usr->next = group->users;
group->users = usr;