#include
#include
class student
{
int number;
char name[20];
char sex[6];
char old[20];
char place[6];
char ment[20];
char clas[10];
public:
student next;
char getname(){ return name;}
int getnumber(){ return number;}
void input()
{
cout<<"\t\t\t按提示輸入:"<
cout>number;
cout<<"\t\t輸入姓名: "; cin>>name;
cout<<"\t\t輸入性別: "; cin>>sex;
cout<<"\t\t輸入年齡: "; cin>>old;
cout<<"\t\t輸入籍貫: "; cin>>place;
cout<<"\t\t輸入系別: "; cin>>ment;
cout<<"\t\t輸入班級: "; cin>>clas;
}
void output()
{
cout<<"學生基本信息如下:"<
cout
}
};
class school
{
public:
school()
{
head=new student;
head->next=NULL;
}
void input();
void mend();
void del();
int find(student **p,int num);
void found();
void show();
void count();
char mainmenu();
private:
student *head;
};
int school::find(student **p1,int num)//子查找函數
{
student *p;
p=head;
while(p->next)
{
(*p1)=p;
if( (p->next)->getnumber()==num)
return 1;
p=p->next;
}
return 0;
}
void school::input() //錄入函數
{
student *p,*p2=NULL;
p=head;
int n;
while(p->next)
p=p->next;
while(n)
{
p2=new student;
p2->input();
p->next=p2;
p2->next=NULL;
p=p->next;
cout<<"\t\t\t按1繼續,按0返回 : ";
cin>>n;
}
}
void school::found() //查找函數
{
student *p;
int num=1;
cout<<"按編號查找: ";
cout<<"\t\t\t輸入編號: ";
cin>>num;
if(!find(&p,num) )
{
cout<<"\t\t找不到你要查找的內容!"<
return;
}
(p->next)->output();
}
void school::del() //刪除函數
{
student *p,*p2;
int num;
cout<<"\t\t\t輸入編號: ";
cin>>num;
if( !find(&p,num) )
{
cout<<"\t\t找不到你要刪除的內容!"<
return;
}
(p->next)->output();
p2=p->next;
p->next=p2->next;
delete p2;
}
void school::show() //顯示函數
{
student *p;
p=head;
while(p->next)
{
(p->next)->output();
p=p->next;
}
}
void school::mend() //修改函數
{
student *p;
int num=1;
cout<<"\t\t\t輸入編號: ";
cin>>num;
if( !find(&p,num) )
{
cout<<"\t\t找不到你要修改的內容!"<
return;
}
(p->next)->output(); (p->next)->input();
}
char school::mainmenu() //主選菜單函數
{
char n[6];
cout<<"————————歡迎進入學籍管理系統————————"<
cin>>n;
return n[0];
}
void main() //主函數
{
school pp;
int k=1;
char n;
while(k==1)
{
n=pp.mainmenu();
switch(n)
{
case '1':; break;
case '2':pp.input(); break;
case '3':pp.found(); break;
case '4':pp.mend(); break;
case '5':pp.del(); break;
case '7':pp.show(); break;
case '0':
break;
}
}
}
http://www.cppblog.com/everyday/archive/2013/07/12/201727.aspx
http://www.cnblogs.com/wouldguan/archive/2012/10/18/2730178.html
http://www.2cto.com/kf/201309/246943.html
你這個就是單鏈表的排序,以上代碼稍作修改即可。