资源描述:
《大数据结构-矩阵地压缩存储程序.doc》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、实用文档实验报告课程名:数据结构(C语言版)实验名:矩阵的压缩存储姓名:班级:学号:时间:2014.11.23实用文档一实验目的与要求1.掌握并实现稀疏矩阵的压缩存储的方法2.在该存储方法上实现矩阵的操作二实验内容•判断一个用二维数组存储的矩阵是不是稀疏矩阵•将其转化为压缩存储的形式•在压缩存储上实现矩阵的乘法和转置操作三实验结果与分析压缩转置程序:#include//判断该矩阵是否为稀疏矩阵#definem10#definen10inta[m][n]={{1,0,0,0,0,
2、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},{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;};struc
3、tthreestu[100];structthree1{inti,j;intvalue;};structthree1stu1[100];intjiance(){实用文档intx=0;//赋初值为0for(x=0;x<=99;x++){stu[x].value=0;}floatt=0;floatv;for(inti=0;i4、n",v);return1;}else{实用文档printf("该矩阵不是稀疏矩阵");return0;}}voidyasuo(){intt=0;for(intr=0;r5、(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};//每一列非0的数目for(x=0;x<=99;x++){stu1[x].value=0;}for(intj=0;j6、f(a[i][j]!=0){num[j]++;t++;}}}intcpot[10]={0,0,0,0,0,0,0,0,0,0};cpot[0]=0;for(j=1;j7、+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;d8、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}