规则矩阵压缩存储c语言程序,c语言矩阵的压缩存储

满意答案

#define N 4

#define M 5

#include

#include

#include

typedef int ElemType;

typedef struct triplist

{

int row,col;

ElemType val;

}tl;

tl a[N*M];

void print_array(ElemType b[][M+1])

{

int i,j;

printf("\n");

for(i=1;i<=N;i++)

{

for(j=1;j<=M;j++)

printf("%5d",b[i][j]);

printf("\n");

}

}

void create_triplist(ElemType b[N][M+1],tl a[ ])

{

int i,j;

int t=1;

for(i=1;i<=N;i++)

for(j=1;j<=M;j++)

if(b[i][j])

{

a[t].row=i;

a[t].col=j;

a[t].val=b[i][j];

t++;

}

a[0].row=N;

a[0].col=M;

a[0].val=t-1;

for(i=1;i<=N*M;i++)

printf("%d\t%d\t%d\n",a[i].row,a[i].col,a[i].val);

}

int main()

{

ElemType b[N+1][M+1]; //这里我把b[N][M+1] 的N后边加一

int e,f;

srand((unsigned)time(NULL));

for(e=1;e<=N;e++)

for(f=1;f<=M;f++)

b[e][f]=rand()/10000;

print_array(b);

create_triplist(b,a);

return 0;

}

看看能不能运行,因为我运行出来的和这个结果都一样,只是有内存问题,加一之后就没有这个提示了

00分享举报

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值