一道c语言题目 急...........拜托啦

来源:百度知道 编辑:UC知道 时间:2024/05/12 20:41:40
编程序(调试通过后将结果粘贴在程序末)
设有链表结点的结构及变量如下:
struct st
{ int num ;
struct st *next;
};
struct st *head, *p1 ,* p2;
编写函数create(),是个无参数函数,创建链表,num=0结束,返回指针值,指向首结点head,并用printlink函数遍历该链表。

1:
struct st *creat(){
head=NULL;
while(1){
p2=new (struct st );
printf("\n输入num:");
cin>>p->num;
if(p->num){
if(!head){head=p2;p1=head;}
else{
p1->next=p2;
p1=p2;
}
}
else break;
}
if(head)delete p2;
return head;
}
2:
void printlink(){
p1=head;
while(p1){
printf("%d ",p1->num);
p1=p1->next;
}

#include <iostream.h>
#include <malloc.h>
struct st
{ int num ;
struct st *next;
};

st *create()
{
struct st *head, *temp, *newNode;
int i = 0;