版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 京东pop售前客服咨询认证考试及答案中级
- 电力安全应急知识题库及答案
- 2026全国特种作业人员高处安装常考题及答案
- 2026年院感知识考试试题及答案
- 2026年音律联觉测试题及答案
- 2026年碳排放管理师认证考试模拟试卷(碳排放核算与交易实务)历年真题及答案
- 2024-2025学年广州市荔湾区八年级下学期期末数学试题及答案
- 质量目标与保证措施
- 不锈钢箔材铜箔材加工生产基地项目可行性研究报告模板-申批备案
- 浙江宁波市海曙区2025-2026学年第二学期期末考试八年级数学试卷及答案
- 铜化集团招聘笔试题及答案
- 苯乙烯安全风险隐患排查指南(试行)
- 苏教版四年级下册数学竖式计算练习200道及答案
- GB/T 46939-2025中医体质分类与判定
- 2026晋能控股集团招聘面试题及答案
- 2026年高中政治学业水平考试重点知识点总结(复习必背)
- 永光化学产品的技术规格书及参数详解
- 高炮广告牌施工方案范本
- 2025年湖北建筑工程技术高、中级职务水平能力测试建筑工程题库含答案详解
- ICU轮转护士工作总结
- 广东省初级注册安全工程师题库及答案解析
评论
0/150
提交评论