关于链表的问题
#include<iostream>using namespace std;
struct Student
{
int ID;
// string name;
Student *next;
};
Student *Create()
{
Student *head,*p1,*p2;
int n=0;
head=NULL;
p1=p2=new Student;
cout<<"请输入用户ID:"<<endl;
cin>>p1->ID;
// cout<<"请输入用户姓名:"<<endl;
// cin>>p1->name;
while(p1->ID!=0)
{
if(n==0)
{
head=p1;
}
else
{
p2->next=p1;
}
p2=p1;
p1=new Student;
cout<<"请输入用户ID:";
cin>>p1->ID;
// cout<<"请输入用户姓名:";
// cin>>p1->name;
n++;
}
p2->next=NULL;
return head;
}
void OutPut(Student *head)
{
Student *p=head;
while(p)
{
cout<<"用户ID:"<<p->ID<<endl;
// cout<<"用户姓名:"<<p->name<<endl;
p=p->next;
}
}
/*void Insert(Student *head)
{
cout<<"输入要插入元素的位置:";
int i;
cin>>i;
cout<<"输入要插入元素的ID:";
int num;
cin>>num;
Student *p,*q,*s;
int k=1;
p=head;
q=p->next;
while(k<i&&q!=NULL)
{
p=q;
q=q->next;
k++;
}
if(k==i)
{
s=new Student;
s->ID=num;
p->next=s;
s->next=q;
cout<<"插入记录成功";
}
}*/
int main()
{
Student *p=Create();
// Insert(p);
OutPut(p);
return 0;
}
这个程序错在哪了?请大家看看