问题代码:
/*问题及代码
*Copyright(c)2016,烟台大学计算机学院
*All right reserved.
*文件名称:1.cpp
*作者:李玲
*完成日期;2016年10月28日
*版本号;v1.0
*问题描述: 将稀疏数组中的非零元素用三元组的方式表示出来
*输入描述:稀疏数组
*程序输出:以行列数三元组表示,以列行数转置后的三元组表示
*/
#include <stdio.h>
#include "tup.h"
int main()
{
TSMatrix t,tb;
int x,y=10;
int A[6][7]=
{
{0,0,1,0,0,0,0},
{0,2,0,0,0,0,0},
{3,0,0,0,0,0,0},
{0,0,0,5,0,0,0},
{0,0,0,0,6,0,0},
{0,0,0,0,0,7,4}
};
CreatMat(t,A);
printf("b:\n");
DispMat(t);
if (Assign(t,x,2,5)==true) //调用时返回true
printf("Assign(t,x,2,5)=>x=%d\n",x);
else //调用时返回false
printf("Assign(t,x,2,5)=>参数错误\n");
Value(t,y,2,5);
printf("执行Value(t,10,2,5)\n");
if (Assign(t,x,2,5)==true) //调用时返回true
printf("Assign(t,x,2,5)=>x=%d\n",x);
else //调用时返回false
printf("Assign(t,x,2,5)=>参数错误\n");
printf("b:\n");
DispMat(t);
TranTat(t,tb);
printf("矩阵转置tb:\n");
DispMat(tb);
return 0;
}
运行结果:
知识点总结:
这个程序的重点在于转置,将行列倒过来,数字不变,只需要找出适合这个数的新的行列表达方式即可。
学习心得:
学会数据结构中的矩阵转置