Quickly make a static linked list

若如初见. 提交于 2019-12-13 22:33:28

问题


I want to quickly make a static linked list, with as little code as possible, which is very readable and without clutter. How do i accomplish this elegantly?

something like

1 -> 2 -> 3 -> 4 -> NULL


回答1:


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))));


来源:https://stackoverflow.com/questions/29192284/quickly-make-a-static-linked-list

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!