[原]链表的简单应用!
#include <iostream>
using namespace std;
struct student
{
int no;
char name[10];
student *next;
};
void chaxun(student *pl)
{
while(pl->next!=NULL)
{
cout<<pl->no<<endl
<<pl->name<<endl;
pl=pl->next;
}
}
student *charu()
{
student *pl;
pl=new student;
cout<<"输入NO"<<endl;
cin>>pl->no;
cout<<"输入NAME"<<endl;
cin>>pl->name;
return pl;
}
int main()
{
int no=0;
student *p=NULL,*head=NULL;
cout<<"***************************************"<<endl;
cout<<"* 1.插入学生信息"<<endl;
cout<<"* 2.输出学生信息"<<endl;
cout<<"* 3.exit"<<endl;
cout<<"***************************************"<<endl;
do
{
cin>>no;
if (no!=1&&no!=2&&no!=3)
{
cout<<"重新输入1-2-3"<<endl;
cin>>no;
}
if(no==1)
{
if(head==NULL)
{
head=charu();
p=head;
}
else
{
p->next=charu();
p=p->next;
}
}
if(no==2)
{
if(head!=NULL)
chaxun(head);
else
cout<<"没有学生信息!"<<endl;
}
if(no==3)
exit(0);
}
while(1);
return 0;
}
见笑了.呵呵
using namespace std;
struct student
{
int no;
char name[10];
student *next;
};
void chaxun(student *pl)
{
while(pl->next!=NULL)
{
cout<<pl->no<<endl
<<pl->name<<endl;
pl=pl->next;
}
}
student *charu()
{
student *pl;
pl=new student;
cout<<"输入NO"<<endl;
cin>>pl->no;
cout<<"输入NAME"<<endl;
cin>>pl->name;
return pl;
}
int main()
{
int no=0;
student *p=NULL,*head=NULL;
cout<<"***************************************"<<endl;
cout<<"* 1.插入学生信息"<<endl;
cout<<"* 2.输出学生信息"<<endl;
cout<<"* 3.exit"<<endl;
cout<<"***************************************"<<endl;
do
{
cin>>no;
if (no!=1&&no!=2&&no!=3)
{
cout<<"重新输入1-2-3"<<endl;
cin>>no;
}
if(no==1)
{
if(head==NULL)
{
head=charu();
p=head;
}
else
{
p->next=charu();
p=p->next;
}
}
if(no==2)
{
if(head!=NULL)
chaxun(head);
else
cout<<"没有学生信息!"<<endl;
}
if(no==3)
exit(0);
}
while(1);
return 0;
}
见笑了.呵呵