




已阅读5页,还剩19页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
中期考核程序汇总1. 两个集合A和B用递增有序的线性链表LA和LB表示,求AB,结果链表用LA表示,LB链表没有保存的必要。#includeusing namespace std;struct Linklistint data;Linklist* next;Linklist* La=NULL;Linklist* Lb=NULL;void Creat(Linklist* &L)Linklist *p,*temp;int d5;int i;L=(Linklist*)malloc(sizeof(Linklist);L-next=NULL;p=L;for(i=0;idi;L-data=d0;for(i=1;idata=di;temp-next=NULL;p-next=temp;p=temp;void Print(Linklist* &L)Linklist* p;p=L;while(p)coutdatanext;coutnext;while(pb)while(pa&(pb-data pa-data)pa1=pa;pa=pa-next;if(pa!=NULL)if(pa-data pb-data)if(pa=La)La=pb;pa1=pb;elsepa1-next=pb;pa1=pa1-next;pb-next=pa;pb=pb1;if(pb1!=NULL)pb1=pb1-next;elseif(pa1-data data)pa1-next=pb;break;elsepb=pb1;if(pb1!=NULL)pb1=pb1-next;void main()Creat(La);Creat(Lb);Print(La);Print(Lb);Sort(La,Lb);Print(La);2. 定义一个串类,实现对串的操作#includeusing namespace std;#define M 50class Stringprivate:char *str;public:String(char *p)/输入一个字符串str=p;coutpendl;bool isNULL()/判空if(str=NULL|Leng()=0)return true;return false;int Leng()/求串长char *p;int len=0;p=str;while(*p)len+;p+;return len;void Delete(int i,int k)/删除部分字符char *p,*q;p=&stri;q=&strk;while(*q)*p=*q;p+;q+;*p=0;coutstr=A&*p=Z)*p+=32;p+;coutstr=a&*p=z)*p-=32;p+;coutstrendl;void main()char aM=aldjSTin;String s(a);coutIs Empty?boolalphas.isNULL()endl;coutthe leng:s.Leng()endl;s.Delete(2,5);s.High();s.Low();3. 定义一个栈类,实现对栈的操作#includeusing namespace std;struct Seqsint MAXNUM;int t;int *a;class Stackprivate:Seqs* palist;public:Seqs* Creat(int m)/创建一个栈palist=(Seqs *)malloc(sizeof(Seqs);if(!palist=NULL)palist-a=(int *)malloc(sizeof(int)*m);if(palist-a)palist-MAXNUM=m;palist-t=-1;return palist;elsefree(palist);coutOut of spacet=-1);void Push(int x)/向栈中压入一个元素if(palist-t=palist-MAXNUM-1)coutOver flowt=palist-t+1;palist-apalist-t=x;void Pop()/从栈中取一个元素if(palist-t=-1)coutUnder flowt=palist-t-1;int Top()/取栈顶元素if(palist-t=-1)coutIt is emptyapalist-t);void main()Stack s;int m;cinm;s.Creat(m); s.Push(1);couts.Top()endl;s.Push(2);couts.Top()endl;s.Pop();couts.Top()endl;4. 求集合A和B的交集,链表表示#includeusing namespace std;struct Linklistint data;Linklist* next;Linklist* La=NULL;Linklist* Lb=NULL;void Creat(Linklist* &L)/创建一个链表Linklist *p,*temp;int d5;int i;L=(Linklist*)malloc(sizeof(Linklist);L-next=NULL;p=L;for(i=0;idi;L-data=d0;for(i=1;idata=di;temp-next=NULL;p-next=temp;p=temp;void Print(Linklist* &L)/打印一个链表Linklist* p;p=L;while(p)coutdatanext;coutnext=NULL;pc=Lc;while(p&q)if(p-data=q-data)temp=(Linklist*)malloc(sizeof(Linklist);temp-data=p-data;temp-next=NULL;pc-next=temp;pc=temp;p=p-next;q=q-next;else if(p-datadata)p=p-next;elseq=q-next;return Lc;void main()Linklist* P;Creat(La);Creat(Lb);Print(La);Print(Lb);P=Inter();Print(P-next);5. 对链表进行排序#includeusing namespace std;#define M 5struct Linklistint data;Linklist* next;Linklist* head=NULL;void Creat()Linklist *p,*temp;int dM;int i;head=(Linklist*)malloc(sizeof(Linklist);head-next=NULL;p=head;for(i=0;idi;for(i=0;idata=di;temp-next=NULL;p-next=temp;p=temp;void Print()Linklist* p; p=head-next;while(p)coutdatanext;coutnext;q=head-next;int bM;int i,j;int count,temp;count=0;while(p)bcount+=p-data;p=p-next;for(i=0;icount-1;i+)for(j=i+1;jbj)temp=bi;bi=bj;bj=temp;for(i=0;idata=bi;q=q-next;void main()Creat();Print();Sort();Print();6. 定义一个时间类,并初始化#includeusing namespace std;class Timeprivate:int hour;int minute;int second;public:Time(int h)hour=h;minute=0;second=0;Time(int h,int m)hour=h;minute=m;second=0;Time(int h,int m,int s)hour=h;minute=m;second=s;void Set(int h,int m,int s)hour=h;minute=m;second=s;void Print()if(hour12)hour=hour%12;couttime:PM:hour:minute:secondendl;elsecouttime:AM:hour:minute:secondendl;void main()Time s(10);s.Set(11,2,33);s.Print();Time x(10,2);x.Set(15,34,45);x.Print();7. 定义一个队列类,并实现对其的操作#includeusing namespace std;struct Seqsint MAXNUM;int f;int r;int *a;class Queueprivate:Seqs* palist;public:Seqs* Creat(int m)palist=(Seqs *)malloc(sizeof(Seqs);if(!palist=NULL)palist-a=(int *)malloc(sizeof(int)*m);if(palist-a)palist-MAXNUM=m;palist-f=0;palist-r=0;return palist;elsefree(palist);coutOut of spacef=palist-r);void Push(int x)if(palist-r+1)%palist-MAXNUM=palist-f)coutFull queueapalist-r=x;palist-r=(palist-r+1)%palist-MAXNUM;void Pop()if(palist-f=palist-r)coutEmpty Queuef=(palist-f+1)%palist-MAXNUM;int Top()if(palist-f=palist-r)coutEmpty Queueapalist-f);void main()Queue s;int m;cinm;s.Creat(m);s.Push(1);couts.Top()endl;s.Push(2);couts.Top()endl;s.Pop();couts.Top()endl;8. 求集合A和B的交集,交集放在数组C中#includei#includeusing namespace std;#define M 5#define N 5int fn(int aM,int bN,int cM+N)int k=0,i;for (i=0;iM;i+)for (int j=0;jN;j+)if(ai=bj)ck+=ai;for(i=0;ik;i+)coutci,;coutendl;return k;void main()int aa5=1,2,3,6,8;int bb5=2,5,6,7,8;int cc10;coutfn(aa,bb,cc)endl;9. 求集合A和B的并集,交集放在数组C中#includeusing namespace std;#define M 5#define N 5int fn(int aM,int bN,int cM+N)int i,j,k;i=0;j=0;k=0;while(iM&jN)if(aibj)ck+=ai+;else if(ai=bj)ck+=ai+;j+;elseck+=bj+;if(i=M)while(jN)ck+=bj+;if(j=N)while(iM)ck+=ai+;for(i=0;ik;i+)coutci,;coutendl;return k;void main()int aa5=1,3,8,9,10;int bb5=2,5,6,8,10;int cc10;coutfn(aa,bb,cc)endl;10.L为没有头结点的单链表的第一个结点的指针,构造三个带头结点的单循环链表表示的线性表#includeusing namespace std;struct Charlchar ch;Charl* next;Charl* head=NULL;Charl* hEng=NULL;Charl* hData=NULL;Charl* hOther=NULL;void Creat()Charl* p,*q;p=head=(Charl *)malloc(sizeof(Charl);p-next=NULL;coutch;if(ch!=&)head-ch=ch;elsereturn;while(1)coutch;if(ch!=&)q=(Charl *)malloc(sizeof(Charl);q-ch=ch;q-next=NULL;p-next=q;p=q;elsebreak;void Print(Charl* p)Charl *q;q=p-next;while(q!=p)coutchnext;coutnext=NULL;p1=hEng;hData=(Charl *)malloc(sizeof(Charl);hData-next=NULL;p2=hData;hOther=(Charl *)malloc(sizeof(Charl);hOther-next=NULL;p3=hOther;while(p4)ch=p4-ch;if(ch=a&ch=A&chch=ch;temp-next=NULL;p1-next=temp;p1=temp;else if(ch=0&chch=ch;temp-next=NULL;p2-next=temp;p2=temp;elsetemp=(Charl *)malloc(sizeof(Charl);temp-ch=ch;temp-next=NULL;p3-next=temp;p3=temp;p4=p4-next;p1-next=hEng;p2-next=hData;p3-next=hOther;void main()Creat();Third();Print(hEng);Print(hData);Print(hOther);11.居民类#includeusing namespace std;class Residentprivate:char* Id;char* Name;char Sex;char* Birth;public:void Add(char* id,char* name,char sex,char* birth)Id=id;Name=name;Sex=sex;Birth=birth;void Delete()Id= ;Name= ;Sex= ;Birth= ;void Show()coutId:Idendl;coutName:Nameendl;coutSex:Sexendl;coutBirth:Birthendl;class Adult:public Residentprivate:char * Edu;char * Occ;public:void Add(char* id,char* name,char sex,char* birth,char* edu,char* occ)Resident:Add(id,name,sex,birth);Edu=edu;Occ=occ;void Delete()Resident:Delete();Edu= ;Occ= ;void Show()Resident:Show();coutEdu:Eduendl;coutOcc:Occendl;class Pm:public Adultprivate:char* Party;public:void Add(char* id,char* name,char sex,char* birth,char* edu,char* occ,char* party)Adult:Add(id,name,sex,birth,edu,occ);Party=party;void Delete()Adult:Delete();Party= ;void Show()Adult:Show();coutParty:Partyendl;void main()Resident r;Adult a;Pm p;r.Add(11041123,zhao,m,19900021);r.Show();r.Delete();r.Show();coutendl;a.Add(11041124,Fang,m,19890123,PostG,student);a.Show();coutendl;p.Add(11041125,Qin,m,19891201,Benke,teacher,Gong);p.Show();12.求一个二维数组的鞍点#includeusing namespace std;#define M 10#define N 10int fn(int a1MN,int m,int n,int b1M2)int i,j,k;int temp,x,y;int count=0;int flag1,flag2;flag2=0;for (i=0;im;i+)temp=a1i0;for(j=1;jtemp)temp=a1ij;y=j;for(k=0,flag1=1;ka1ky) flag1=0;if(flag1)b1count0=i;b1count1=y;count+;coutthe an dian is a1iy the position is i,yendl;flag2=1; if(!flag2)coutnot exitendl;return count;void main()int m,n;int aMN,bM2;int c;coutinput m and n mn;for (int i=0;im;i+)for (int j=0;jaij; c=fn(a,m,
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年事业单位招聘考试卫生类医学影像专业知识试卷(高级)
- 教育创新案例毛细管电泳仪在生物实验教学中的应用
- 保健品养护知识培训内容课件
- 2024年北京市崇文区职工大学招聘真题(行政管理岗)
- 2025年护士资格内科护理模拟试题及答案
- 2025年公开选拔中小学校长笔试试题及答案
- 2025年公共卫生危机应对能力测试试卷及答案
- 2025年PCB精密定位材料项目发展计划
- 《Im going to study computer science(第五课时)》课件
- 2025年红外光学石英玻璃合作协议书
- 中医艾灸养生护理
- 2025届湖南省长沙市一中物理高一上期中达标检测模拟试题含解析
- 工程施工重点、难点分析及保证措施
- 2024城市电缆线路岩土工程勘察规范
- 变电站巡检维护服务方案
- 华为质量回溯(根因分析与纠正预防措施)模板
- 2023版评审准则和CNAS对照表
- CATIA CAA 二次开发详细教程(11) 程序的发布
- 分布式光伏发电项目可行性分析报告(方案)讲解演示模板ppt课件-图文
- 高空作业安全刷漆施工方案
- 医疗康养项目运营方案
评论
0/150
提交评论