Transpose of Sparse Matrix

Source: Internet
Author: User


It is best to use tc2.0 in Chinese

# Include <stdio. h>
# Define N 10
Typedef struct {
Int I, j;
Int e;
} TsMatrix;
Typedef struct {
TsMatrix data [N];/* the maximum length is N */
Int mu, nu, tu;
} TSMatrix;

Int FastTransposeSMatrix (TSMatrix M, TSMatrix * T)
{
Int col, p, q, t;
Int num [N], cpot [N];

T-> mu = M. nu; T-> nu = M. mu; T-> tu = M. tu;
If (T-> tu)
{
For (col = 1; col <= M. nu; ++ col) num [col] = 0;
For (t = 1; t <= M. tu; ++ t) ++ num [M. data [t]. j];
Cpot [1] = 1;
For (col = 2; col <= M. nu; ++ col)
Cpot [col] = cpot [col-1] + num [col-1];
For (p = 1; p <= M. tu; ++ p)
{Col = M. data [p]. j; 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 printM (TSMatrix * M)
{
Int p, q; int t = 1;
For (p = 1; p <= M-> mu; p ++)
{
For (q = 1; q <= M-> nu; q ++)
{If (M-> data [t]. I = p & M-> data [t]. j = q)
{Printf ("% d", M-> data [t]. e); t ++ ;}
Else printf ("0 ");}
Printf ("n");} printf ("nn ");
}

Void main ()
{
TSMatrix A, T; int k;
Printf ("Enter the size of the matrix :");
Printf ("its row:"); scanf ("% d", & A. mu );
Printf ("its columns:"); scanf ("% d", & A. nu );
Printf ("enter A length not greater than 10 and not 0:"); scanf ("% d", & A. tu );
For (k = 1; k <= A. tu; k ++)
{Printf ("Enter the number of % d: n", k );
Printf ("its row location:"); scanf ("% d", & A. data [k]. I );
Printf ("its column location:"); scanf ("% d", & A. data [k]. j );
Printf ("its value:"); scanf ("% d", & A. data [k]. e );
}
Printf ("n original matrix: n ");
PrintM (& );
FastTransposeSMatrix (A, & T );
Printf ("transposed matrix: n ");
PrintM (& T );
}


<

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.