资源描述:
《数据结构~矩阵的压缩存储程序》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、实验报告课程名:数据结构(C语言版)实验名:矩阵的压缩存储姓名:班级:学号:时间:2014.11.23一实验目的与要求1.掌握并实现稀疏矩阵的压缩存储的方法2.在该存储方法上实现矩阵的操作二实验内容•判断一个用二维数组存储的矩阵是不是稀疏矩阵•将其转化为压缩存储的形式•在压缩存储上实现矩阵的乘法和转置操作三实验结果与分析压缩转置程序:#include//判断该矩阵是否为稀疏矩阵#definem10#definen10inta[m][n]={{1,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,
2、0,0,0,0,0,0},{1,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,7,0},{0,0,0,0,0,0,8,0,0,0},{0,0,0,0,0,0,0,0,0,0},};structthree{inti,j;intvalue;};structthreestu[100];structthree1{inti,j;intvalue;};structthree1stu1[100];intjiance(){
3、intx=0;//赋初值为0for(x=0;x<=99;x++){stu[x].value=0;}floatt=0;floatv;for(inti=0;i4、[c]!=0){stu[t].i=r;stu[t].j=c;stu[t].value=a[r][c];t++;}}}}voiddisplay(){intx=0;printf("压缩矩阵的三元组为:");for(x=0;x<=99;x++){if(stu[x].value==0)break;printf("{%d,%d,%d}",stu[x].i,stu[x].j,stu[x].value);}printf("");}voidzhuanzhi(){intx=0;//赋初值为0intt=0;intnum[10]={0,0,0,0,0,0,0,0,0,0};/
5、/每一列非0的数目for(x=0;x<=99;x++){stu1[x].value=0;}for(intj=0;j6、;stu1[q].j=stu[k].i;stu1[q].value=stu[k].value;++cpot[col];}}voiddisplay1(){intx=0;printf("转置以后的三元组为:");for(x=0;x<=99;x++){if(stu1[x].value==0)break;printf("{%d,%d,%d}",stu1[x].i,stu1[x].j,stu1[x].value);}printf("");}voiddisplay2(){intd,b;for(d=0;d7、"%d",a[d][b]);}printf("");}}voidmain(){display2();if(jiance()==1){yasuo();display();zhuanzhi();display1();}}图1:压缩转置程序运行结果矩阵的乘法程序:#include#definem13#definen14#definem24#definen22inta1[m1][n1]={{3,0,0,5},{0,-1,0,0},{2,0,0,0},};inta2[m2][n2]={{0,2},{1,0},{-2,4},{0,0},};struct
8、three1{inti,