⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 matrix.cpp

📁 数据结构测试程序
💻 CPP
字号:
// matrix.cpp: implementation of the matrix class.
//
//////////////////////////////////////////////////////////////////////

#include "matrix.h"
#include "stdio.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

matrix::matrix()
{

}

matrix::~matrix()
{

}

int matrix::initate()
{

	mu=nu=tu=0;
	return 1;
}

int matrix::input_mat()
{
	int i,j,m,n;
	element x;
	printf("\nInput the row and col of the matrix(less than 20):");
	scanf("%d%d",&m,&n);
	while(m>20 || m<1 || n>20 || n<1)
	{
		printf("\nIllegal row or col number!\nPlease reinput:");
		scanf("%d%d",&m,&n);
	}

	mu=m,nu=n,tu=0;
	rpos[0]=0;
	printf("\nInput all numbers of the matrix:\n");
	for(i=0;i<m;i++)
	{
		rpos[i+1]=rpos[i];
		for(j=0;j<n;j++)
		{
			scanf("%d",&x);
			if(x)
			{
				data[tu].i=i+1;
				data[tu].j=j+1;
				data[tu].v=x;
				tu++;
				rpos[i+1]++;
			}
		}
	}
	return 1;
}

void matrix::show_mat()
{
	if(mu && nu && tu)
	{
		int p;
		for(p=0;p<tu;p++)
		{
			printf("%3d %3d %5d\n",data[p].i,data[p].j,data[p].v);
		}
		putchar('\n');
	}
	else
	{
		printf("0 matrix!\n");
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -