【发布时间】:2015-03-22 08:12:40
【问题描述】:
我想快速做一个静态链表,代码尽量少,可读性好,不杂乱。我如何优雅地做到这一点?
类似
1 -> 2 -> 3 -> 4 -> NULL
【问题讨论】:
标签: c linked-list
我想快速做一个静态链表,代码尽量少,可读性好,不杂乱。我如何优雅地做到这一点?
类似
1 -> 2 -> 3 -> 4 -> NULL
【问题讨论】:
标签: c linked-list
struct node {int x; struct node *next;};
#define cons(x,next) (struct node[]){{x,next}}
struct node *head = cons(1, cons(2, cons(3, cons(4, NULL))));
【讨论】:
x 和指针 next。这里next 将是下一个node[] 或NULL 的地址。
(struct node[]){{x,next}} 这样的语句怎么可能在语法上是正确的。这个语句是初始化吗?你能举出与 C 语言中通常使用的类似的例子吗?
{}太多了。