稀疏矩阵转置的三个算法(数据结构)

您所在的位置:网站首页 三元组矩阵转置算法 稀疏矩阵转置的三个算法(数据结构)

稀疏矩阵转置的三个算法(数据结构)

2024-07-11 05:49| 来源: 网络整理| 查看: 265

稀疏矩阵转置经典算法

#include //系数矩阵三元组表的定义 #define MAXSIZE 1000 #define M 6 #define N 7 //稀疏矩阵转置的经典算法 //void TransMatrix(int source[M][N], int dest[N][M]) void TransMatrix(int (*source)[N], int (*dest)[M]) { int i = 0; int j = 0; //二维数组 for ( i = 0; i n = A.n; if (B->len) { for (col = 1; col len; col++) num[col] = 0; for (t = 1; t len; t++) num[A.data[t].col]++;//下标计数法计算每一列的非零元素的个数 position[1] = 1; for (col = 2; col data[q].col = A.data[p].row; B->data[q].e = A.data[p].e; position[col]++; } } } int main() { int i = 0; TSMatrix a; TSMatrix b; a.m = 6; a.n = 7; a.len = 8; a.data[1].row = 1; a.data[1].col = 2; a.data[1].e = 12; a.data[2].row = 1; a.data[2].col = 3; a.data[2].e = 9; a.data[3].row = 3; a.data[3].col = 1; a.data[3].e = -3; a.data[4].row = 3; a.data[4].col = 6; a.data[4].e = 14; a.data[5].row = 4; a.data[5].col = 3; a.data[5].e = 24; a.data[6].row = 5; a.data[6].col = 2; a.data[6].e = 18; a.data[7].row = 6; a.data[7].col = 1; a.data[7].e = 15; a.data[8].row = 6; a.data[8].col = 4; a.data[8].e = -7; printf("原稀疏矩阵的三元组:\n"); for (i = 1; i


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3