hello Everyone!
I want to implement fast transpose of a sparse matrix. It's really hard for me to understand the algorithm explained in book.
Can anyone please explain in simple manner?
Thank you ! :)

Simple. A matrix is made up of rows and columns. Given a matrix with 3 rows and 3 columns:
1 2 3
4 5 6
7 8 9

After transpose you have:
1 4 7
2 5 8
3 6 9

Simple algorithm:

A ^= B
B ^= A
A ^= B

Swaps without temporary storage.

I know transpose of a matrix. I want to know about "fast transpose" method of a sparse matrix.

Call a function transopose(*x, *y) and pass the address of the items to swap. You can use the xor method described in my previous post to do the swap. First call would swap item 2 in col 1 with item 2 in row 1. and so on.

``````void ftrans(int a[][3],int b[][3])
{
int i,j,k=0,min,pos=0,c[20][3];
for(i=0;i<=a[0][2];i++)
{
for(j=0;j<3;j++)
c[i][j]=a[i][j];
}
b[k][0]=c[pos][1];
b[k][1]=c[pos][0];
b[k][2]=c[pos][2];
for(j=c[0][2];j>0;j--)
{
min=c[0][1];
for(i=c[0][2];i>0;i--)
{
if(c[i][1]<=min&&c[i][2]!=0)
{
min=c[i][1];
pos=i;
}
}
k++;
b[k][0]=c[pos][1];
b[k][1]=c[pos][0];
b[k][2]=c[pos][2];
c[pos][2]=0;
}
}``````

simple funda hai yr n it works only whn........your input function is as follows

``````void input(int a[][3],int r,int c)
{
int n,i,j,k=0;
a[0][0]=r;
a[0][1]=c;
a[0][2]=0;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&n);
if(n!=0)
{
++k;
a[k][0]=i;
a[k][1]=j;
a[k][2]=n;
a[0][2]++;
}
}
}
}``````
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.