




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、第二题:建立一个线性链表,其元素值为:包括学号、姓名、性别、年龄等信息。并依次从键盘输入(输入时要有相应的提示)以输入0结束,然后依次输出线性链表中的各元素值。#include "stdlib.h"#include "stdio.h"#define null 0#define size 40struct node char num6; char name8; char sex2; int age; struct node * next; ;void main () int x; struct node * head; struct node * p,*
2、q; head=(struct node *)malloc(size); p=head; printf("if exit:pleas into '0' "); scanf("%d",&x); while (x!=0) q=(struct node *)malloc(size); printf("numn"); scanf("%s",q->num); printf("namen"); scanf("%s",q->name); printf(&
3、quot;sexn"); scanf("%s",q->sex); printf("agen"); scanf("%d",&q->age); p->next=q; p=q; printf("if exit:pleas into '0' "); scanf("%d",&x); p->next=null; p=head; printf("n num name sex age n");while (p!=null)pr
4、intf("%8s%8s%6s%6dn",p->num,p->name,p->sex,p->age);p=p->next;void main () int x,iage,find=0; struct node * head; struct node * p,* q,*pt; head=(struct node *)malloc(size); p=head; printf("if exit:pleas into '0' "); scanf("%d",&x); while (x!=0)
5、 q=(struct node *)malloc(size); printf("numn"); scanf("%s",q->num); printf("namen"); scanf("%s",q->name); printf("sexn"); scanf("%s",q->sex); printf("agen"); scanf("%d",&q->age); p->next=q; p=q; printf
6、("if exit:pleas into '0' "); scanf("%d",&x); p->next=null; p=head; printf("n num name sex age n");while (p!=null)printf("%8s%8s%6s%6dn",p->num,p->name,p->sex,p->age);p=p->next;printf("pleas into age :n");scanf("%d&q
7、uot;,&iage);pt=head;p=pt;pt=pt->next;while (pt!=null) if(pt->age=iage) p->next=pt->next; find=1; else p=pt; pt=pt->next;if(find=0)printf("no find %d ",iage);else p=head; printf("n num name sex age n");while (p!=null)printf("%8s%8s",p->num,p->nam
8、e);printf("%8s%5dn",p->sex,p->age);p=p->next;第四题:现在假设有两个多项式a(x)=7x8+6x5+12x2-9;b(x)=3x11+10x8+8x2编写一个程序将这两个多项式相加,输出两个多项式及相加的结果#include<stdio.h>#include<stdlib.h>typedef struct polynode int coef; int exp; struct polynode *next;PNode;PNode *Creat_Linkst(int n);void PolyA
9、dd(PNode *pa,PNode *pb);void Print_Linkst(PNode *H);main() PNode *HA,*HB; int la,lb; printf("enter la,lb:"); scanf("%d,%d",&la,&lb); printf("ncreat HAn");HA=Creat_Linkst(la); printf("A(x)=");Print_Linkst(HA); printf("ncreat HBn");HB=Creat_Lin
10、kst(lb); printf("B(x)=");Print_Linkst(HB); PolyAdd(HA,HB); printf("nA(x)+B(x)=");Print_Linkst(HA);PNode *Creat_Linkst(int n) PNode *head,*p,*s; int i; head=(PNode*)malloc(sizeof(PNode); head->next=NULL; p=head; printf("enter coef,exp:n"); for(i=1;i<=n;+i) s=(PNode
11、 *)malloc(sizeof(PNode);scanf("%d,%d",&s->coef,&s->exp);s->next=NULL;p->next=s;p=s; return(head);void PolyAdd(PNode *pa,PNode *pb) PNode *pre,*qa,*qb,*q; int sum; pre=pa; qa=pa->next; qb=pb->next; while(qa&&qb) if(qa->exp=qb->exp) sum=qa->coef+qb->coef; if(sum)qa->coef=sum;pre=qa; elsepre->next=qa->next;free(qa); qa=pre->next; q=qb;qb=qb->next;free(q); if(qb)pre->next=qb; free(pb); void Print_Linkst(PNode *H)PNode *p;p=H->
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 故事解读草房子中的成长与坚持
- 跨境支付合同
- 恐龙世界探索之旅故事解读
- 科技公司办公家具的现代简约风格报告
- 码头船舶安全管理体系构建与优化培训汇报
- 酒店项目经营管理合同
- 规章制度实施细节与常见问题解答
- 科技产品设计的创新之路结构设计挑战与机遇
- 知识版权在办公环境中的保护措施
- 寓言故事狐狸与乌鸦的智慧评析
- 2025年01月福建省福利彩票发行中心片区管理员招考笔试历年典型考题(历年真题考点)解题思路附带答案详解
- 健身新人直播流程
- 城乡规划管理与法规系列讲座课件-城市规划依法行政案例
- 企业的生产过程课件
- 法规解读丨2024新版《突发事件应对法》及其应用案例
- JGJ46-2024 建筑与市政工程施工现场临时用电安全技术标准
- 2024年世界职业院校技能大赛高职组“关务实务组”赛项参考试题库(含答案)
- 企业动火作业安全管理制度范文
- 2024年新疆公务员考试申论试题(县乡卷)
- 自来水企业安全教育培训
- 河北美术出版社小学六年级下册书法练习指导教案
评论
0/150
提交评论