- /*
- * Copyright (c)2016,烟台大学计算机与控制工程学院
- * All rights reserved.
- * 文件名称:wu.cpp
- * 作 者:武昊
- * 完成日期:2016年10月27日
- * 版 本 号:v1.0
- *问题描述:建立稀疏矩阵三元组表示的算法库,包括:
- ① 头文tup.h,定义数据类型,声明函数;
- ② 源文件tup.cpp,实现稀疏矩阵三元组表示的基本运算,主要算法包括:
- void CreatMat(TSMatrix &t,ElemType A[M][N]); //从一个二维稀疏矩阵创建其三元组表示
- bool Value(TSMatrix &t,ElemType x,int i,int j); //三元组元素赋值
- bool Assign(TSMatrix t,ElemType &x,int i,int j); //将指定位置的元素值赋给变量
- void DispMat(TSMatrix t); //输出三元组
- void TranTat(TSMatrix t,TSMatrix &tb);//矩阵转置
- ③ 设计main函数,测试上面实现的算法
- *输入描述:无
- *程序输出:测试结果
- */
tup.h:
- #ifndef TUP_H_INCLUDED
- #define TUP_H_INCLUDED
- #define M 6
- #define N 7
- #define MaxSize 100 //矩阵中非零元素最多个数
- typedef int ElemType;
- typedef struct
- {
- int r; //行号
- int c; //列号
- ElemType d; //元素值
- } TupNode; //三元组定义
- typedef struct
- {
- int rows; //行数
- int cols; //列数
- int nums; //非零元素个数
- TupNode data[MaxSize];
- } TSMatrix; //三元组顺序表定义
- void CreatMat(TSMatrix &t,ElemType A[M][N]); //从一个二维稀疏矩阵创建其三元组表示
- bool Value(TSMatrix &t,ElemType x,int i,int j); //三元组元素赋值
- bool Assign(TSMatrix t,ElemType &x,int i,int j); //将指定位置的元素值赋给变量
- void DispMat(TSMatrix t);//输出三元组
- void TranTat(TSMatrix t,TSMatrix &tb);//矩阵转置
- #endif // TUP_H_INCLUDED
main.cpp: