欢迎来到天天文库
浏览记录
ID:39640017
大小:40.50 KB
页数:4页
时间:2019-07-08
《学生课程管理》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include#includetypedefstructstudent{longintnum;charname[20];structstudent*next;}stud;stud*create_list();intinsert_list(stud*head,char*name,intn);intdel_list(stud*head,char*name);stud*find_list(stud*head,char*name);voidbrow_list(stud*head
2、);voidmain(){stud*head;intchoice;charname[8];head=NULL;cout<<"1.建立链表";cout<<"2.插入新生";cout<<"3.查找学生";cout<<"4.删除学生";cout<<"5.数据浏览";cout<<"0.退出程序";do{cout<<"请选择操作(输入0-5)";cin>>choice;if(choice>5
3、
4、choice<0){cout<<"输入错误!a";continue;}switch(choice)
5、{case1:if(head==NULL)head=create_list();break;case2:if(head==NULL){cout<<"链表未建立!";break;}while(1){cout<<"姓名(输入0结束):";cin>>name;if(strcmp(name,"0")==0)break;insert_list(head,name,-1);}break;case3:cout<<"输入姓名:";cin>>name;find_list(head,name);break;case4:cout<<
6、"输入姓名:";cin>>name;del_list(head,name);break;case5:brow_list(head);break;default:return;}}while(1);}stud*create_list(){stud*head;head=newstud;if(head!=NULL)cout<<"链表已建立!";elsecout<<"没有足够内存空间!a";head->next=NULL;head->num=0;returnhead;}intinsert_list(stud*he
7、ad,char*name,intn){stud*p,*q,*s;s=newstud;if(s==NULL){cout<<"没有足够内存空间!a";return0;}q=head;p=head->next;while(p!=NULL&&n!=q->num){q=p;p=p->next;}q->next=s;s->next=p;strcpy(s->name,name);s->num=q->num+1;return1;}stud*find_list(stud*head,char*name){stud*p;p=hea
8、d;while(p!=NULL&&strcmp(p->name,name)){p=p->next;}if(p!=NULL){cout<<"学号:"<num<<"姓名:"<name<<"";}elsecout<<"查无此人!";returnp;}intdel_list(stud*head,char*name){stud*p,*q;q=head;p=head->next;while(p!=NULL&&strcmp(p->name,name)){q=p;p=p->next;}if(p!=NULL)
9、{q->next=p->next;deletep;cout<<"删除完成!";return1;}else{cout<<"查无此人!a";return0;}}voidbrow_list(stud*head){stud*p;p=head->next;while(p!=NULL){cout<<"学号:"<num<<"姓名:"<name<<"";p=p->next;}}
此文档下载收益归作者所有