我想得到含100000个元素的链表,即100000个结构体相连;请问在c语言中怎么实现?注意按常规方法不是行的。

来源:百度知道 编辑:UC知道 时间:2024/06/04 22:04:18
请用malloc ();

动态内存分配不行吗。Windows可以管理虚拟内存的啊

#include <stdio.h>
#include <stdlib.h>
struct nood
{
long value;
struct nood * next;
};
main()
{
struct nood head;
struct nood *now;
struct nood *temp;
long i;
head.next=&head;
now=&head;
for(i=1;i<=100000;i++)
{
temp=malloc(sizeof(struct nood));
temp->value=i;
now->next=temp;
now=temp;
}
now=head.next;
head.next=&head;
for(i=1;i<=100000;i++)
{
printf("%d\t",now->value);
temp=now;
now=now->next;
free(temp);
}
now=&head;
}