#include "stdafx.h" #include <iostream>using namespace std;typedef int DataType; #define SIZE 100typedef Struct{int I,j;datatype e;} Triple;typedef struct{triple data[size+1];int Mu,nu,tu;} Tsmatrix;void transpose (Tsmatrixm,tsmatrix &t) {//interchange row number t.mu = M.tu; t.nu = m.mu; T.tu = M.tu;if (t.tu) {int q = 1;for (int col =1;col<m.nu;++col) {for (int p=1;p<m.tu;++p) {if (m.data[p].j = 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;++q;}}}} void Input1 (Tsmatrix &m) {printf ("Input nu mu tu (with a space interval) of a matrix:\n"); scanf_s ("%d%d%d", m.nu,m.mu,m.tu); Row,colume,and tu printf ("Please input the data of matrix:\n"); for (int c=1;c<=m.tu;c++) {scanf_s ("%d", &m.data[c].i); scanf_s ("%d", &M.DATA[C].J); scanf_s ("%d", &M.DATA[C].E); }//for}int Printm (Tsmatrix T) {printf ("Matrix after transpose is:\n"); for (int c=1;c<=t.tu;c++) {printf ("%d%d%d\n", T.data[c].i,t.data[C].J,T.DATA[C].E]; }//for return 1; }//input void Fasttranspose (Tsmatrix m,tsmatrix &t) {//interchange row number t.mu = M.tu; t.nu = m.mu; T.tu = M.tu;int cpot[size+1],num[size+1];if (m.tu) {for (int col=1;col<m.mu;col++) num[col]=0;for (int t=1;t<M.tu; t++) ++num[m.data[t].j];cpot[1] = 1;for (int col=2;col<m.mu;col++) cpot[col]=cpot[col-1]+num[col-1];for (int p=1;p <m.tu;++p) {int col = m.data[p].j;int q = cpot[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; ++cpot[col]; }}}/*void Main () {Tsmatrix M; Tsmatrix t;input1 (M); Fasttranspose (m,t); Printm (M);} */
Inversion of sparse matrices (normal inversion and normal inversion)