C++实现稀疏矩阵的十字链表表示法

本文详细介绍了如何使用C++实现稀疏矩阵的十字链表表示法,包括矩阵的初始化、插入元素、删除元素和矩阵运算等操作。通过这种方法,可以高效地处理大量为零的元素,降低存储开销并提升计算效率。
摘要由CSDN通过智能技术生成

/*
 * OLMat.h
 *
 *  Created on: Oct 17, 2015
 *      Author: chris
 */

#ifndef OLMAT_H_
#define OLMAT_H_

#include<iostream>

typedef int ElemType;

struct OLNode{
	int i, j;
	ElemType e;
	OLNode *right, *down;

	OLNode():i(0), j(0),
			right(NULL), down(NULL) {}
};

struct OLMat{
	OLNode *rhead, *chead;
	int mu, nu, tu;

	OLMat(): rhead(NULL), chead(NULL),
			mu(0), nu(0), tu(0) {}
};

bool OLMatCreate(OLMat & mat, int nrows, int ncols);
void OLMatDestroy(OLMat & mat);

bool OLMatPutVal(OLMat & mat, int i, int j, ElemType e);
bool OLMatGetVal(OLMat & mat, int i, int j, ElemType& e);
bool OLMatDelEnt(OLMat & mat, int i, int j);

bool OLMatInput(OLMat & mat);
void OLMatPrint(OLMat & mat);

void OLMatTranspose(OLMat & mat);

#endif /* OLMAT_H_ */



/*
 * OLMat.cpp
 *
 *  Created on: Oct 17, 2015
 *      Author:
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值