/*
檔名稱:jcy
作 者:賈存鈺
完成日期:2023年10月24日
問題描述:建立稀疏矩陣三元組表示的演算法庫,包括:
① 頭文tup.h,定義資料型別,宣告函式;
② 原始檔tup.cpp,實現稀疏矩陣三元組表示的基本運算.
*/[cpp]view plain
copy
#ifndef tup_h_included
#define tup_h_included
#define m 6
#define n 7
#define maxsize 100 //矩陣中非零元素最多個數
typedef
intelemtype;
typedef
struct
tupnode; //三元組定義
typedef
struct
tsmatrix; //三元組順序表定義
void
creatmat(tsmatrix &t,elemtype a[m][n]);
//從乙個二維稀疏矩陣建立其三元組表示
bool
value(tsmatrix &t,elemtype x,
inti,
intj);
//三元組元素賦值
bool
assign(tsmatrix t,elemtype &x,
inti,
intj);
//將指定位置的元素值賦給變數
void
dispmat(tsmatrix t);
//輸出三元組
void
trantat(tsmatrix t,tsmatrix &tb);
//矩陣轉置
#endif // tup_h_included
[cpp]view plain
copy
#include "stdio.h"
#include "tup.h"
void
creatmat(tsmatrix &t,elemtype a[m][n])
//從乙個二維稀疏矩陣建立其三元組表示
} } bool
value(tsmatrix &t,elemtype x,
inti,
intj)
//三元組元素賦值
t.data[k].r=i;
t.data[k].c=j;
t.data[k].d=x;
t.nums++;
} return
true
;
//成功時返回true
} bool
assign(tsmatrix t,elemtype &x,
inti,
intj)
//將指定位置的元素值賦給變數
void
dispmat(tsmatrix t)
//輸出三元組
void
trantat(tsmatrix t,tsmatrix &tb)
//矩陣轉置
} }
[cpp]view plain
copy
#include
#include "tup.h"
intmain()
, ,
, ,
,
};
creatmat(t,a);
printf("b:\n"
);
dispmat(t);
if(assign(t,x,2,5)==
true
) //呼叫時返回true
printf("assign(t,x,2,5)=>x=%d\n"
,x);
else
//呼叫時返回false
printf("assign(t,x,2,5)=>引數錯誤\n"
);
value(t,y,2,5);
printf("執行value(t,10,2,5)\n"
);
if(assign(t,x,2,5)==
true
) //呼叫時返回true
printf("assign(t,x,2,5)=>x=%d\n"
,x);
else
//呼叫時返回false
printf("assign(t,x,2,5)=>引數錯誤\n"
);
printf("b:\n"
);
dispmat(t);
trantat(t,tb);
printf("矩陣轉置tb:\n"
第八周 專案2
程式的版權和版本宣告部分 檔名稱 object.cpp 完成日期 2013年 4 月 23日 版本號 v1.0 輸入描述 無 問題描述 程式輸出 略。include using namespace std class ctime void settime int h,int m,int s void...
第八周 專案3 2
檔名稱 main.cpp 作者 孫彩虹 完成日期 2015年11月16日 問題描述 試編寫演算法,實現將已知字串所有字元倒過來重新排列。include ifndef sqstring h included define sqstring h included define maxsize 100 最...
第八周 專案3 3
檔名稱 main.cpp 作者 孫彩虹 完成日期 2015年11月16日 問題描述 從串s中刪除其值等於c的所有字元。include ifndef sqstring h included define sqstring h included define maxsize 100 最多的字元個數 ty...