建立一个采用链式存储的线性表,表中元素为学生,每个学生信息包含姓名、学号和成绩三部分,对该表实现:选读.docx

建立一个采用链式存储的线性表,表中元素为学生,每个学生信息包含姓名、学号和成绩三部分,对该表实现:选读.docx

  1. 1、本文档共24页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
云南大学物理实验教学中心实验报告课程名称:计算机软件技术基础实验项目:线性表(链式存储)及其应用学生姓名:学号:学院系级专业指导教师:实验时间:年时分至时分实验地点:实验类型:教学(演示□验证□综合█设计□)学生科研□课外开放□测试□其它□一、实验目的:掌握链式存储结构下线性表的建立及基本操作。二、问题:建立一个采用链式存储的线性表,表中元素为学生,每个学生信息包含姓名、学号和成绩三部分,对该表实现:①输出、②查找、③插入、④删除功能,并计算出平均成绩和总成绩。三、程序的编写与调试1、原程序:#includeiostream#includeiomanipusing namespace std;struct node { int num; char name[10]; float score; node *next;};class linked_list {private:node *head;public:linked_list();void prt_linked_list();void ins_num_linked_list(int i,node *b);void ins_name_linked_list(char name[],node *b);int del_num_linked_list(node);int del_name_linked_list(node);int sear_num_linked_list(int);void sear_name_linked_list(node);void count_linked_list();}/*建立链表*/ linked_list::linked_list(){node *p,*q;p=new node;q=new node;p-num=101;strcpy(p-name,aaa);p-score=98; q-num=104;strcpy(q-name,ddd);q-score=95; head=p;p-next=q;q-next=NULL; return ;}/* 输出*/void linked_list::prt_linked_list(){node *p;p=head;if(head==NULL){cout空链表!”endl;return;}elsedo{coutp-num p-name p-scoreendl;p=p-next;}while(p!=NULL);return;}/*按学号插入*/void linked_list::ins_num_linked_list(int i,node *b) {node *q;if(head==NULL){b-next=NULL;head=b;return;}if(head-num==i){b-next=head;head=b;return;}q=head;while((q-next!=NULL)(((q-next)-num)!=i))q=q-next;if(q-next==NULL){cout无此元素endl;return;} b-next=q-next;q-next=b; return;}/*按姓名插入*/void linked_list::ins_name_linked_list(char name[],node *b){node *q;if(head==NULL){b-next=NULL;head=b;return;}if(strcmp(head-name,name)==0){b-next=head;head=breturn;}q=head;while((q-next!=NULL)(strcmp((q-next)-name,name)!=0))q=q-next;if(q-next==NULL){cout无此元素endl;return;} b-next=q-next;q-next=b; return;}/*按学号删除*/int linked_list::del_num_linked_list( node x ) {node *p,*q;if(head==NULL){cout空链表!endl;return 0;}if(head-num==x.num){p=head-next;delete head;head=p;return 1;}q=head;while((q-next!=NULL)(((q-next)-num)!=x.num))q=q-next;if(q-next==0){cout链表中无此元素endl;return 0;}p=q-next;q-next=p-next;delete p;return 1;}/*按姓名删除*/int linked_list::del_name_

文档评论(0)

1112111 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档