C 언어로 특수 매트릭스 저장
삼원조 순서 저장 방법 & 전환
#include
#include
#define MAXSIZE 12500
//
// written at 2018-6-1 23:37:22
typedef int ElemType;
typedef struct{
int i; // row
int j; // column
ElemType e;
}tripple;
typedef struct{
tripple data[MAXSIZE+1]; // 0 not use
int mu, nu, tu; // , ,
}tsMatrix;
tripple init_tribble(int i, int j, ElemType e){
tripple temp;
temp.i = i;
temp.j = j;
temp.e = e;
return temp;
}
void print_sparse_matrix(tsMatrix temp){
printf("**********START************
");
printf("i\tj\tv\t
");
for (int i=1; i<=temp.tu; i++){
printf("%d\t%d\t%d\t
",temp.data[i].i,temp.data[i].j,temp.data[i].e);
}
printf("***********END*************
");
}
void transposeMatrix(tsMatrix m, tsMatrix *t){
//
t->mu = m.nu; // step 1
t->nu = m.mu; // step 1
t->tu = m.tu;
// step 2 & step 3
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 quickTranspose(tsMatrix m, tsMatrix *t){
// M b.data ,
t->mu = m.nu;
t->nu = m.mu;
t->tu = m.tu;
if (t->tu){
int num[m.nu + 1]; // 0 not use
for (int col=1; col<=m.nu; col++) num[col] = 0; // num
for (int temp=1; temp<=m.tu; temp++) ++num[m.data[temp].j];
int cpot[m.nu + 1]; // 0 not use
cpot[1] = 1; //
// col b.data
for (int col=2; col<=m.nu;++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(){
// init the martix and let the matrix not empty
tsMatrix temp;
temp.data[1] = init_tribble(1, 2, 12);
temp.data[2] = init_tribble(1, 3, 9);
temp.data[3] = init_tribble(3, 1, -3);
temp.data[4] = init_tribble(3, 6, 14);
temp.data[5] = init_tribble(4, 3, 24);
temp.data[6] = init_tribble(5, 2, 18);
temp.data[7] = init_tribble(6, 1, 15);
temp.data[8] = init_tribble(6, 4, -7);
// 97 M
temp.mu = 6;
temp.nu = 7;
temp.tu = 8;
print_sparse_matrix(temp);
tsMatrix t;
tsMatrix t2;
transposeMatrix(temp, &t2);
quickTranspose(temp, &t);
printf("\t \t
");
print_sparse_matrix(t2);
printf("\t \t
");
print_sparse_matrix(t);
}
출력 결과는 다음과 같습니다.
**********START************
i j v
1 2 12
1 3 9
3 1 -3
3 6 14
4 3 24
5 2 18
6 1 15
6 4 -7
***********END*************
**********START************
i j v
1 3 -3
1 6 15
2 1 12
2 5 18
3 1 9
3 4 24
4 6 -7
6 3 14
***********END*************
**********START************
i j v
1 3 -3
1 6 15
2 1 12
2 5 18
3 1 9
3 4 24
4 6 -7
6 3 14
***********END*************
행 논리 링크 순서표
#include
#include
#define MAXSIZE 12500
/*
written at 2018-6-2 18:26:30
*/
typedef int ElemType;
typedef struct{
int i; // row
int j; // column
ElemType e;
}tripple;
typedef struct RLSMatrix{
tripple data[MAXSIZE+1];
int mu, nu, tu;
int rops[MAXRC + 1]; //
}RLSMatrix;
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.