几核处理器好:C语言创建单链表问题

来源:百度文库 编辑:高校问答 时间:2024/04/19 21:13:38
怎样通过一个CREAT()函数,创建一个单链表,能让MAIN使用,且MAIN可以利用CREAT()创建的head进行插入删除等其他操作?
我现在只能在main中建立单链表,高手点拨!给出creat()和main如何做调用,是把head建在main中,其他在creat()中吗?

main()
{
node *head,*p,*s;
int x,i,cyc=1;
head=(node *)malloc(sizeof(node));
p=head;
while(cyc)
{
scanf("%d",&x);
if(x!=0)
{
s=(node *)malloc(sizeof(node));
s->data=x;
p->next=s;
p=s;
}
else cyc=0;
}
head=head->next;
p->next=NULL;/*删除头尾*/
-----------------以上是main中创建单链表,以下无关。---------------
printf("Find :\n");
scanf("%d",&x);
find(head,x);
printf("All=%d\n",length(head));
printf("Input after i");
scanf("%d",&i);
putch('\n');
printf("Insert =");
scanf("%d",&x);
putch('\n');
ransack(head);
insert(head,i,x);
printf("New All=%d\n",length(head));
ransack(head);
printf("What to del\n");
scanf("%d",&x);
del(head,x);
printf("New2 All=%d\n",length(head));
ransack(head);
getch();

}
书上错误太多 估计写书的人都自己没编译通

这个问题好像好多书上都有哦
自己没有用心去看书那、、

用C++简单多了阿