说明
在这里稀疏矩阵的输入用的是三元组的这种方式输入的,毕竟是稀疏矩阵嘛下面也有对应的txt文件,代码同样采用文本形式输入,毕竟要输入的内容比较多,有对FILE不了解的朋友,可以先简单预览:测试用例必备技能之FILE函数的基本运用(小白篇)
有问题欢迎大家指正、评论或者私信!
代码实现
完整代码需要私聊我噢,下面展示的是部分代码~🍝🍝
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdarg.h>
#define MAXSIZE 20
#define OK 1;
#define ERROR -1;
#define OVERFLOW -2;
#define Status int ;
#define Elemtype char
#define MElemType_TSq int
typedef struct node {
int i, j;
MElemType_TSq e;//非零元素的行、列的下标
}Triple;
//三元稀疏矩阵的类型定义
typedef struct {
Triple data[MAXSIZE + 1];
int mu, nu, tu;//矩阵的行数、列数、非零元个数
}TSMatrix;
//基本的函数
//int Create(FILE* fp, int n, TSMatrix* M, ...);//创建
void Print(TSMatrix M);
void Destroy(TSMatrix* M);
测试用例
测试用例:
num.txt:
HT.txt:
完整代码需要私聊我噢,谢谢~🍝🍝