稀疏矩阵三元组转置代码C语言
时间: 2023-11-22 22:47:38 浏览: 149
以下是稀疏矩阵三元组转置的C语言代码:\n\```\#inclu <stdi.h>\#defi MAXSIZE 12500\n\ypedef stru {\ i i, j;\ i ;\} Trip;\n\ypedef stru {\ Trip [MAXSIZE + 1];\ i mu, nu, tu;\} TSMatrix;\n\voi TransposSMatrix(TSMatrix M, TSMatrix *T) {\ i p, q, ;\ i num[M.u + 1], cp[M.u + 1];\ T->mu = M.u;\ T->u = M.mu;\ T->u = M.u;\ if (T->u) {\ for ( = 1; <= M.u; ++) {\ num[] = ;\ }\ for (p = 1; p <= M.u; p++) {\ = M.[p].j;\ num[]++;\ }\ cp[1] = 1;\ for ( = 2; <= M.u; ++) {\ cp[] = cp[ - 1] + num[ - 1];\ }\ for (p = 1; p <= M.u; p++) {\ = M.[p].j;\ q = cp[];\ T->[q].i = M.[p].j;\ T->[q].j = M.[p].i;\ T->[q]. = M.[p].;\ cp[]++;\ }\ }\}\n\i mai() {\ TSMatrix M, T;\ i i, j, k;\ printf(\请输入矩阵的行数、列数和非零元素个数:\\\");\ scanf(\"%%%\", &M.mu, &M.u, &M.u);\ printf(\请输入矩阵的三元组:\\\");\ for (k = 1; k <= M.u; k++) {\ scanf(\"%%%\", &M.[k].i, &M.[k].j, &M.[k].);\ }\ TransposSMatrix(M, &T);\ printf(\转置后的矩阵的三元组为:\\\");\ for (k = 1; k <= T.u; k++) {\ printf(\"% % %\\\", T.[k].i, T.[k].j, T.[k].);\ }\ retur ;\}\n\```\n\
阅读全文