稀疏矩阵压缩算法严蔚敏的算法详解
程序代码: 5.2.2 稀疏矩阵的压缩存储方法
一、三元组顺序表
算法 5.1
void FastTransposeSMatrix(TSMatrix M, TSMatrix &T)
{
T.rows = M.cols;
T.cols = M.rows;
T.terms = M.terms;
if (T.terms) {
for (col=1; col<=M. cols; ++col)
num[col] = 0;
for (t=1; t<=M. terms; ++t)
++num[M.data[t].j]; // 我就是这里看不明白。
rpos[1] = 1;
for (col=2; col<=M. cols; ++col)
rpos[col] = rpos[col-1] + num[col-1];
//
for (p=1; p<=M.terms; ++p) { //
col = M.data[p].j; q = rpos[col];
T.data[q].i =M.data[p].j;
T.data[q].j =M.data[p].i;
T.data[q].e =M.data[p].e;
++rpos[col];
} // for
} // if
} // FastTransposeSMatrix 最好是附上代码有详解的注解









