国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

三元組轉置

2023-01-11 07:27 作者:就叫大嘴吧  | 我要投稿


#include <stdio.h>
#include <stdlib.h>
#define Max 100

//三元組結構體的定義 
typedef struct{
	// 非零元所在行、所在列 
	int row, col;
	// 非零元的值 
	int value;		
}Triple;
 
//三元組容器的定義 
typedef struct{
	// data[0] 未使用 
	Triple data[Max];
	// 矩陣為 m行、n列 ?
	int m, n;
	// 矩陣非零元個數(shù)
	int len; 
}TSMatrix;
 
//實現(xiàn)轉置 
void TransposeSMatrix(TSMatrix A, TSMatrix &B){
	
	int i, col;
	// 矩陣 A m行、n列 ?轉置為 矩陣 B n行、m列 
	B.m = A.n;
	B.n = A.m;
	B.len = A.len;
	// q 表示Triple數(shù)組下標,從 1 開始,data[0] 未使用 ?
	int q = 1;
	
	// col <= A矩陣的列數(shù),控制的是 當前遍歷的是 A矩陣的列 ?
	for(col = 1; col <= A.n; ++col){	
		// 每一次 遍歷一遍 Triple數(shù)組 
		for(i = 1; i <= A.len; ++i){
			// 若 當前元素的列標 == col(矩陣 A 的第 col 列) 
			if(A.data[i].col == col){
				// A的列 轉換為 B的行 
				B.data[q].row = A.data[i].col;
				// A的行 轉換為 B的列 
				B.data[q].col = A.data[i].row;
				// 賦 非零元 的值 
				B.data[q].value = A.data[i].value;
				// 數(shù)組下標后移一位 
				++q;
			}
		}
	} 
}

void inputTSMatrix(TSMatrix &T){
	int i, j, value, k; 
	printf("請輸入矩陣行數(shù)、列數(shù):");
	scanf("%d %d", &T.m, &T.n);
	printf("請輸入三元組 非零元個數(shù):");
	scanf("%d", &T.len);
	for(k = 1; k <= T.len; k++){
		printf("請輸入第 %d 個非零元:行 列 值:", k);
		scanf("%d %d %d", &i, &j, &value);
		T.data[k].row = i;
		T.data[k].col = j;
		T.data[k].value = value;
	}
}

void printTSMatrix(TSMatrix T){
	for(int i = 1; i <= T.len; ++i ){
		printf("%d	%d	%d\n", T.data[i].row, T.data[i].col, T.data[i].value);
	}
}

int main(){

	TSMatrix A,B;
	inputTSMatrix(A);

	TransposeSMatrix(A, B);

	printf("\n原始三元組為:\n");
	printTSMatrix(A);
	
	printf("\n轉置后:\n");
	printTSMatrix(B);
	
	return 0;
}


三元組轉置的評論 (共 條)

分享到微博請遵守國家法律
乳源| 扶绥县| 西林县| 潮安县| 平泉县| 弥渡县| 武鸣县| 北海市| 中西区| 台江县| 宣威市| 内乡县| 新田县| 琼海市| 泾源县| 宁明县| 渭源县| 秭归县| 资兴市| 湘乡市| 读书| 遵义市| 湖州市| 丹江口市| 三台县| 东港市| 永胜县| 牡丹江市| 彭水| 上饶市| 专栏| 岳池县| 房产| 澳门| 邯郸市| 九龙城区| 黄骅市| 清新县| 柳河县| 湘潭县| 闻喜县|