这个程序该怎么修改?

来源:百度知道 编辑:UC知道 时间:2024/06/17 04:06:54
#include <iostream.h>
struct std
{ long num;
char name[10];
struct std *next;
};

struct std *create()
{
struct std *head,*p;
head=p=new struct std;
cout<<"请输入学号 姓名 退出输入0:"<<endl;
cin>>p->num>>p->name;
while(p->num!=0)
{
p->next=new struct std;
p=p->next;
cout<<"请输入学号 姓名 退出输入0:"<<endl;
cin>>p->num>>p->name;
}
p->next=NULL;
p=head;
// while(p->next->next=NULL) {p=p->next;}
// p->next=NULL;
while(p->next->next!=NULL)
p=p->next; // delete(p->next);
return head;
}

struct std *insert(struct std *head)
{
struct std *q=head;
while(q->next!=NULL)
{
q=q->next;
}
q=q->next=new struct std;
cout<<"请输入学号 姓名 退出输入0:"<<endl;
cin

改一下creat函数就可以了:

struct std *create()
{
struct std *head,*p;

int n;char a[10];

head=p=new struct std;
cout<<"请输入学号 姓名 退出输入0:"<<endl;
cin>>n>>a;
while(n!=0)
{

p->num=n;
strcpy(p->name,a); //这个函数不记得格式是否正确。

p->next=new struct std;
p=p->next;
cout<<"请输入学号 姓名 退出输入0:"<<endl;
cin>>n>>a;
}

return head;
}