欢迎来到天天文库
浏览记录
ID:52657481
大小:713.50 KB
页数:48页
时间:2020-04-12
《数组集合矩阵习题.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、两个有序集合的并集算法a={12381215}元素个数为m=6b={2379}元素个数为n=4c={}pqk1p2pq3pq7q8p9q12p15pkkkkkkkk01234567两个有序集合的并集算法intset_union(inta[],intm,intb[],intn,intc[]){intp=0,q=0,k=0;while(p2、合a的剩余元素a[4],a[5]直接放入并集c中c[k]=b[q];q++;k++;}else{//集合b已经处理完毕,将集合a的剩余元素a[4],a[5]直接放入并集c中c[k]=a[p];p++;k++;}returnk;}两个有序集合的交集算法intset_insection(inta[],intm,intb[],intn,intc[]){intp=0,q=0,k=0;while(p3、ept(inta[],intm,intb[],intn,intc[]){intp=0,q=0,k=0;while(pvoidmain(void){inti;inta[6]={1,2,3,8,12,15};intb[4]={2,3,7,12};intc[6];intk=set_except(a,6,b,4,c4、);printf("%d",k);for(i=0;i5、7.编写函数,对给定两个有序(升序)一维数组a,b,对a,b合并,构成有序数组c。程序填空:1000021000321004321054321main(){inta[5][5],i,j;for(i=0;i<5;i++){for(j=0;j<5;j++){if(【1】)a[i][j]=0;elsea[i][j]=【2】;printf("%3d",a[i][j]);}printf("");}}【分析】这类题的元素值排列很有规律,一般要从分析行列数i、j与元素值的关系着手.当i=j时,元素值随行数i增加而增加,随列数j增加而减小,这样就很容易得出其元素值与i,j的6、关系是i+1-j。1000021000321004321054321a[5][5]分析:a00a01a02a03a04a10a11a12a13a14a20a21a22a23a24a30a31a32a33a34a40a41a42a43a44main(){inta[5][5],i,j;for(i=0;i<5;i++){for(j=0;j<5;j++){if(【1】)a[i][j]=0;elsea[i][j]=【2】;printf("%3d",a[i][j]);}printf("");}}i7、1a22a23a24a30a31a32a33a34a40a41a42a43a441000021000321004321054321【例4-6】(杨辉三角形)a[i]a[i-1][j-1]a[i-1][j]#include"stdio.h"#defineN30#defineSPACE32voidmain(void){inta[N][N]={0};inti,j,n;printf("输入杨辉三角形阶数:");sca
2、合a的剩余元素a[4],a[5]直接放入并集c中c[k]=b[q];q++;k++;}else{//集合b已经处理完毕,将集合a的剩余元素a[4],a[5]直接放入并集c中c[k]=a[p];p++;k++;}returnk;}两个有序集合的交集算法intset_insection(inta[],intm,intb[],intn,intc[]){intp=0,q=0,k=0;while(p3、ept(inta[],intm,intb[],intn,intc[]){intp=0,q=0,k=0;while(pvoidmain(void){inti;inta[6]={1,2,3,8,12,15};intb[4]={2,3,7,12};intc[6];intk=set_except(a,6,b,4,c4、);printf("%d",k);for(i=0;i5、7.编写函数,对给定两个有序(升序)一维数组a,b,对a,b合并,构成有序数组c。程序填空:1000021000321004321054321main(){inta[5][5],i,j;for(i=0;i<5;i++){for(j=0;j<5;j++){if(【1】)a[i][j]=0;elsea[i][j]=【2】;printf("%3d",a[i][j]);}printf("");}}【分析】这类题的元素值排列很有规律,一般要从分析行列数i、j与元素值的关系着手.当i=j时,元素值随行数i增加而增加,随列数j增加而减小,这样就很容易得出其元素值与i,j的6、关系是i+1-j。1000021000321004321054321a[5][5]分析:a00a01a02a03a04a10a11a12a13a14a20a21a22a23a24a30a31a32a33a34a40a41a42a43a44main(){inta[5][5],i,j;for(i=0;i<5;i++){for(j=0;j<5;j++){if(【1】)a[i][j]=0;elsea[i][j]=【2】;printf("%3d",a[i][j]);}printf("");}}i7、1a22a23a24a30a31a32a33a34a40a41a42a43a441000021000321004321054321【例4-6】(杨辉三角形)a[i]a[i-1][j-1]a[i-1][j]#include"stdio.h"#defineN30#defineSPACE32voidmain(void){inta[N][N]={0};inti,j,n;printf("输入杨辉三角形阶数:");sca
3、ept(inta[],intm,intb[],intn,intc[]){intp=0,q=0,k=0;while(pvoidmain(void){inti;inta[6]={1,2,3,8,12,15};intb[4]={2,3,7,12};intc[6];intk=set_except(a,6,b,4,c
4、);printf("%d",k);for(i=0;i5、7.编写函数,对给定两个有序(升序)一维数组a,b,对a,b合并,构成有序数组c。程序填空:1000021000321004321054321main(){inta[5][5],i,j;for(i=0;i<5;i++){for(j=0;j<5;j++){if(【1】)a[i][j]=0;elsea[i][j]=【2】;printf("%3d",a[i][j]);}printf("");}}【分析】这类题的元素值排列很有规律,一般要从分析行列数i、j与元素值的关系着手.当i=j时,元素值随行数i增加而增加,随列数j增加而减小,这样就很容易得出其元素值与i,j的6、关系是i+1-j。1000021000321004321054321a[5][5]分析:a00a01a02a03a04a10a11a12a13a14a20a21a22a23a24a30a31a32a33a34a40a41a42a43a44main(){inta[5][5],i,j;for(i=0;i<5;i++){for(j=0;j<5;j++){if(【1】)a[i][j]=0;elsea[i][j]=【2】;printf("%3d",a[i][j]);}printf("");}}i7、1a22a23a24a30a31a32a33a34a40a41a42a43a441000021000321004321054321【例4-6】(杨辉三角形)a[i]a[i-1][j-1]a[i-1][j]#include"stdio.h"#defineN30#defineSPACE32voidmain(void){inta[N][N]={0};inti,j,n;printf("输入杨辉三角形阶数:");sca
5、7.编写函数,对给定两个有序(升序)一维数组a,b,对a,b合并,构成有序数组c。程序填空:1000021000321004321054321main(){inta[5][5],i,j;for(i=0;i<5;i++){for(j=0;j<5;j++){if(【1】)a[i][j]=0;elsea[i][j]=【2】;printf("%3d",a[i][j]);}printf("");}}【分析】这类题的元素值排列很有规律,一般要从分析行列数i、j与元素值的关系着手.当i=j时,元素值随行数i增加而增加,随列数j增加而减小,这样就很容易得出其元素值与i,j的
6、关系是i+1-j。1000021000321004321054321a[5][5]分析:a00a01a02a03a04a10a11a12a13a14a20a21a22a23a24a30a31a32a33a34a40a41a42a43a44main(){inta[5][5],i,j;for(i=0;i<5;i++){for(j=0;j<5;j++){if(【1】)a[i][j]=0;elsea[i][j]=【2】;printf("%3d",a[i][j]);}printf("");}}i7、1a22a23a24a30a31a32a33a34a40a41a42a43a441000021000321004321054321【例4-6】(杨辉三角形)a[i]a[i-1][j-1]a[i-1][j]#include"stdio.h"#defineN30#defineSPACE32voidmain(void){inta[N][N]={0};inti,j,n;printf("输入杨辉三角形阶数:");sca
7、1a22a23a24a30a31a32a33a34a40a41a42a43a441000021000321004321054321【例4-6】(杨辉三角形)a[i]a[i-1][j-1]a[i-1][j]#include"stdio.h"#defineN30#defineSPACE32voidmain(void){inta[N][N]={0};inti,j,n;printf("输入杨辉三角形阶数:");sca
此文档下载收益归作者所有