《数据结构》习题课(一)课件

上传人:我*** 文档编号:145276608 上传时间:2020-09-18 格式:PPT 页数:15 大小:36KB
返回 下载 相关 举报
《数据结构》习题课(一)课件_第1页
第1页 / 共15页
《数据结构》习题课(一)课件_第2页
第2页 / 共15页
《数据结构》习题课(一)课件_第3页
第3页 / 共15页
《数据结构》习题课(一)课件_第4页
第4页 / 共15页
《数据结构》习题课(一)课件_第5页
第5页 / 共15页
点击查看更多>>
资源描述

《《数据结构》习题课(一)课件》由会员分享,可在线阅读,更多相关《《数据结构》习题课(一)课件(15页珍藏版)》请在金锄头文库上搜索。

1、数据结构习题课(一)邓万宇数据结构-C语言描述陈一华编,第一章,Main() int I,j,p; for(I=1;I=9;I+) printf(“%d”,I); for (I=1;I=2;I+) printf(“n”); for (I=1;I=9;I+) for(j=1;j=I;j+) p=I*j; printf(“%5d”,p); for(j=1;j=2;j+) printf(“n”); ,9次,2次,45次,18次,共74次,第二章,1.void Nizhi(int a,int n) int I,temp; for (I=1;I=n2;I+) temp=aI; ai=an-I+1; an

2、-I+1=temp; ,2. Int getNO(NODE *h,int x) NODE *p; int NO; p=h; NO=0; while(p!=NULL ,3.int getNodeCount(NODE *h) NODE *p; int count; count =0; p=h; while p!=NULL count=count+1; p=p-next; return count; ,4.方法1:利用原数组 DelEqual(Elements List, int *n) for( i=1;i= *n -1;i+) for(j=i+1;j= *n;j+) if Listi=Listj

3、 /相同的节点j if j= *n *n = *n -1; else for (k=j+1;k= *n;k+) Listk-1=Listk ,4.方法2:另外申请一个数组 DelEqual(Elements List, int *n) Elements NewList; len=0; NewList1=List1; len+; for (i=2;ilen len+; NewListlen=Listi; List=NewList; *n=len; ,5.void insert(NODE *h, int a,int x) NODE *p,*pre s=(NODE*)Malloc(sizeof(NO

4、DE); s-data=x; s-next=NULL; p=h; while(p!=NULL ,6. NODE * Combine(NODE *X,NODE *Y) int n,m;NODE *p,*Z; n=0; m=0; p=X; while p!=NULL n+; p=p-next; p=Y; while p!=NULL m+; p=p-next; p=X;q=Y; if mnext; q-next=p-next; p-next=q; p=q-next; q=Y; return X; else while p!=NULL X=X-next; p-next=q-next; q-next=p

5、; q=p-next; p=X; return Y;,8.NODE *Nizhi2(NODE*h) NODE *p; p=q=h-next; h-next=NULL; while(p!=NULL) p=p-next; q-next=h; h=q; q=p; return h; ,h,p,q,h,14.NODE * Combine2(NODE*pa,NODE*pb) NODE *qa,*qb; qa=pa-next; pre=pa; qb=pb-next; while qa!=pa ,pa,pb,qa,qb,pre,补充1:建立单连表的算法CreatList_L(Lnode *L , int n

6、 ),要求顺序输入n个元素的值(即先输入a1,a2.).,CreatList_L(Lnode *L , int n) LinkList *q,*p; L= (Lnode *) molloc (sizeof (Lnode);/头结点 L-next=NULL; q=L; For(i=1;idata); p-next=NULL;q-next=p;q=p; ,补充2:矩阵转置完整代码,#define MAX 50 typedef struct node int row , col; float val;NODE; NODE matrix100; /创建矩阵(三元组) CreatMatrix() int

7、 num; println(“Please input non-zero elements number:”); scanf(“%d,i+) scanf(“%d %d %d”, b0.i = a0.j; b0.j=a0.i; b0.val=a0.val; t=b0.val; /non-zero number if t0 for(col=1;col=n;col+) numcol=0; for(k=1;k=t;k+) numak.j=numak.j+1; /每列非0元素个数 pot1=1; for(col=1;col=n;col+) potcol=potcol-1+numcol-1; for(k=

8、1;k=t;k+) col=ak.j; q=potcol; bq.i=ak.j; bq.j=ak.i; bq.val=ak.val; potcol+; ,/输出矩阵 outputMatrix1 (NODE matrix ) int t=matrix0.val; for (int i=0;it;i+) println(“%d, %d, %d n”, matrixi.row, matrixi.col, matrixi.val outputMatrix2 (NODE matrix ) int t=matrix0.val; int rowNum=matrix0.row; int colNum=matrix0.col; for (int i=0; i rowNum-1;i+) for (int j=0; j colNum-1;j+) int flag=0; for (k=1;kt;k+) if (matrixk.row=i ,

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > PPT模板库 > PPT素材/模板

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号