链表创建为什么需要使用内存分配?

来源:互联网 发布:微信公众平台修改域名 编辑:程序博客网 时间:2024/05/24 16:15


假如有1000个已经声明的结构体,能否直接创建链表?应该是可以的,但这样就违背了链表出现的作用了(动态扩展),因为已经提前定义了1000个……

struct MyStruct{int a;struct MyStruct* next;};int main(void){struct MyStruct node[6];int k;for (int i = 0; i < 5; i++){scanf("%d", &k);node[i].a = k;node[i].next = &node[i + 1];}node[5].a = 44;node[5].next = NULL;struct MyStruct* temp = &node[0];while (temp!= NULL){printf("%d", temp->a);temp = temp->next;}getchar(); getchar(); return 0;}


0 0
原创粉丝点击