版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 《GB-T 39941-2021木家具生产过程质量安全状态监测与评价方法》专题研究报告
- 《GBT 13698-2015 二氧化铀芯块中总氢的测定》专题研究报告
- 《宠物鉴赏》课件-宠物鱼的简介
- 2026年河南工业和信息化职业学院单招职业技能考试题库带答案详解
- 运动健康管理指导协议
- 钟表行业钟表维修高级技师岗位招聘考试试卷及答案
- 2025年高新区预防接种合格证培训考核试题及答案
- 2025年常州市城管协管人员招聘笔试备考试题及答案解析
- 2025年刺绣机电控项目发展计划
- 高钾食物的选择与益处
- 2025中央广播电视总台招聘144人笔试历年题库附答案解析
- 2026年瓦工职业技能鉴定考试题库及答案
- 2025年云南省人民检察院聘用制书记员招聘(22人)笔试考试参考题库及答案解析
- 胃肠外科围手术期护理要点
- 竣工资料归档与管理流程
- 购车合伙协议书模板
- 二手摩托车买卖合同范本
- 2026年山西省财政税务专科学校单招职业倾向性测试题库附答案
- 2025年阿里辅警协警招聘考试备考题库及答案1套
- 黄宝康药用植物学课件
- 2025年天车工(初级)考试试卷及模拟题库及答案
评论
0/150
提交评论