版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、1.顺序表#include#includeTypedef structInt numchar name20; Sqstusq stu stu4;Sqstu studvoid creat();void insert();void del();Void main()creat();Printf(“输入要插入学生的信息: n”);insert();Printf(请输入学编号:以删除学生。 n );del();Void creat()int I;for(I=0);i3;I)scanf(“% d % s”,stu I)。num,stu I。name);Printf(学生的信息包括: n );for(I=
2、0);i3;I)printf(“%-10d % s n”,stu I)。num,stu I。name);Void insert()Int i、j;scanf(“% d % s”,stud.num,stud . name);for(I=0);Stud.numstui。numI)j=I;for(I=3);ij;I-)Stui。num=stui-1。numStrcpy (stu I)。name,stu I-1。name);Stuj 1。num=stud.numStrcpy(stuj 1)。name、stud . name);Printf(现在,学生的信息是: n );for(I=0);i4;I)pr
3、intf(“%-10d % s n”,stu I)。num,stu I。name);Void del()int I;scanf(“% d”,stud . num);for(I=0);Stud.num!=stui。numI)I=ifor(I);i4;I)stuI=stuI 1;Printf(现在,学生的信息是: n );for(I=0);i3;I)printf(“%-10d % s n”,stu I)。num,stu I。name);2.链接的列表#include#include#define NULL 0#define LEN sizeof(struct student)Struct stud
4、entInt numchar name20;Struct student * nextint n;Struct student * creat()Struct student * headStruct student * p1、* p2n=0;P1=p2=(struct student *)malloc(len);scanf(“% d % s”,p1-num,P1-name);Head=NULLWhile (p1-num!=0)n=n 1;If(n=1)Head=p1Elsep2-next=P1;P2=p1P1=(struct student *)malloc(LEN);scanf(“% d
5、% s”,p1-num,P1-name);p2-next=NULL;Return headVoid print(struct student * head)struct student * p;printf(“ n now,these% d记录阵列: n”,n);P=headIf (head!=NULL)Doprintf(“% d,%sn”,p-num,p-name);p=p-next;While (p)!=NULL);struct student * insert(struct student * head,structstudent * stud)Struct student * p0、*
6、 p1、* p2P1=headP0=studIf (head=NULL)Head=p0P0-next=NULL;Elsewhile(P0-num P1-num)(P1-next!=NULL)P2=p1P1=P1-next;If (p0-num=p1-num)If (head=P1)Head=p0Elsep2-next=P0;P0-next=P1;ElseP1-next=P0;P0-next=NULL;n=n 1;Return headstruct student * del(struct student * head,intnum)Struct student * p1、* p2P1=head
7、If (head=NULL)Printf(n列表空! n );Return headWhile (num!=p1-num) (p1-next!=NULL)P2=p1P1=P1-next;If (num=p1-num)If(p1=head)head=P1-next;Elsep2-next=P1-next;Printf(delete:%dn ,num);n=n-1;ElsePrintf(%d not been found!n ,num);Return headVoid main()Struct student * head、* stuInt del _ numprintf( input recor
8、ds : n );head=creat();打印(head);printf(“ n input the inserted record :”);stu=(struct student *)malloc(LEN);scanf(“% d % s”,stu-num,stu-name);Head=insert(head,stu);打印(head);printf( n input the deleted number : );scanf(“% d”,del _ num);Head=del(head,del _ num);打印(head);3.堆栈#include#define MaxSize 3Type
9、def structint dataMaxSize;Int top StackVoid InitStack(Stack S) /空堆栈s . top=-1;Int push(Stack S,int x) /堆栈If (S.top=MaxSize-1)return 0;Elses . top=s . top 1;s . datas . top=x;return 1;Int gettop(Stack S,int x) /堆栈顶部元素If (S.top=-1)return 0;Elsex=s . datas . top;return 1;Int pop(Stack S,int x) /堆栈If (S
10、.top=-1)return 0;Elsex=s . datas . top;s . top-;return 1;Int StackEmpty(Stack S) /确定堆栈为空If (S.top=-1)return 1;Elsereturn 0;Void main()stack S;Int x、I=0;init stack(S);printf(立即开始创建堆栈,输入3个数据! n );Doscanf(“% d”,x);Push(S,x);I; while(I 3);Printf(获取堆栈顶部元素为: n );printf(“%-10d n”,s . datas . top);Printf(“元
11、素按顺序堆叠: n”);I=0;DoPop(S,x);printf(“%-10d”,x);I; while(I 3);4.链队列#include#include# define NULL 0;Typedef structqmodeInt dataStructqmode * next qmode,* queue ptrTypedef structQueuePtr frontQueuePtr rear链接队列;queue ptr p;Int InitQueue(LinkQueue Q) /空队列配置q . front=q . rear=(queue ptr)malloc(size of(qmode
12、);If(!Q.front)return 0;q . front-next=NULL;return 1;Int EnQueue(LinkQueue Q,int e) /入队p=(queue ptr)malloc(size of(qmode);If(!p)return 0;p-data=e;p-next=NULL;q . rear-next=p;q . rear=p;return 1;Int DeQueue(LinkQueue Q,int e) /取消队列If (Q.front=Q.rear)return 0;p=q . front-next;e=p-data;q . front-next=p-
13、next;If (Q.rear=p)q . rear=q . front;自由(p);return 1;Void main()链接队列q;int e;init queue(Q);Printf(立即开始入队,输入3个数据!要结束,请输入0! n );Doscanf(“% d”,e);EnQueue(Q,e);while(e)!=0);Printf(“删除队列标头元素示例: n”);DeQueue(Q,e);printf(“%-10d”,e);Printf(n请输入要入队的元素!要结束,请输入0! n );Doscanf(“% d”,e);EnQueue(Q,e);while(e)!=0);5.循环队列#include#include#define MAXSIZE 5Typedef structint dataMAXSIZE;Int front,rearInt num Queuequeue q;Int x、I;Void kongdui()q . front=q . rear=0;Void jindui(Queue q,int x) /分组算法If(q.num=MAXSIZE)Printf(团队已满! n );q . rear=(q . rear 1)% max
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 健身指导员职业资格证运动生理学专项习题及答案
- 2026年全民健身服务指导员初级考试专项训练题库及答案
- 2026年心理咨询师二级考试心理咨询技能综合测试专项题库冲刺练习题库及答案
- 2026年无人机驾驶员执照考试无人机飞行器电气系统与电子设备习题集及答案
- 企业安全生产标准化评审员培训模拟试卷及答案
- 河北省廊坊市霸州市2026年七年级上学期期中数学试题附答案
- 辽宁成考专升本英语真题含答案解析
- 湖北成考高升专数学理考前摸底真题题
- 2026广东广州市黄埔区萝岗街道综合发展中心招聘环卫工人2人笔试参考题库及答案解析
- 2026上海交通大学基础医学院上海市生殖医学重点实验室研究助理招聘1人笔试备考试题及答案解析
- 中小学楷书书写规范教学
- 检验检测机构法律法规政策培训测试题及答案
- 5.1.3小数乘法(课件)(共20张)西师大版(新教材)五年级上册
- 护理副高职称评审答辩自我介绍模板
- 2026年陕西省基层法律工作者题库及答案
- 中国国新招聘笔试
- 2026年河南省大学语文专升本真题及答案
- 人工智能(AI)通识考试试卷附答案
- T∕CCIASC 0054-2026 人工智能芯片 面向芯粒的卡间互联接口技术要求
- 物业应急管理培训课件
- 儿科医院现场答辩面试题及答案
评论
0/150
提交评论