CH4_2.C
上传用户:lgb298
上传日期:2013-03-22
资源大小:1025k
文件大小:1k
- #include <stdio.h>
- #define N 9
- #define M 8
- typedef struct node
- { int i,j,v;
- }JD;
- int fast_transpos(JD ma[],JD mb[])
- { int n,col,p,k,t;
- int num[M],cpot[M];
- n=ma[0].j;
- t=ma[0].v;
- mb[0].i=n; mb[0].j=ma[0].i; mb[0].v=t;
- if(t<=0)
- return(0);
- for(col=0;col<=n;col++)
- num[col]=0;
- for(p=1;p<=t;p++)
- { k=ma[p].j;
- num[k]++;
- }
- cpot[0]=0; cpot[1]=1;
- for(col=2;col<=n;col++)
- cpot[col]=cpot[col-1]+num[col-1];
- for(p=1;p<=t;p++)
- { col=ma[p].j;
- k=cpot[col];
- mb[k].i=ma[p].j;
- mb[k].j=ma[p].i;
- mb[k].v=ma[p].v;
- cpot[col]++;
- }
- return(1);
- }
- void main()
- { JD ma[N]={{6,7,8},{1,2,12},{1,3,9},{3,1,-3},
- {3,6,14},{4,3,24},{5,2,18},{6,1,15},{6,4,-7}};
- JD mb[N];
- int i;
- fast_transpos(ma,mb);
- for(i=0;i<N;i++)
- printf("%d,%d,%dn",mb[i].i,mb[i].j,mb[i].v);
- }