上了一点课,第一次写链表,摸索着写了,但是无法输出,可以帮忙看看吗
#include<iostream>
using namespace std;
struct link
{
int number;
char name[100];
char sex;
int age;
struct link *next;
};
int main()
{
struct link *head;
head=new link;
head->next=NULL;
struct link *p,*pr;
pr=new link;
head=pr;
for(int i=0;i<5;i++)
{
p=new link;
cin>>p->number;
cin>>p->name;
cin>>p->sex;
cin>>p->age;
pr=p;
pr->next=NULL;
}
while(head!=NULL)
{
cout<<head->number<<" ";
cout<<head->name<<" ";
cout<<head->sex<<" ";
cout<<head->age<<" ";
head=head->next;
cout<<endl;
}
}
上了一点课,第一次写链表,不知道哪里出了错,可以帮忙看看吗,万分感谢