[题目分析]设稀疏矩阵是AmxnHm是总表头指针设rch是行列表头指针则rch>right=rch时该行无非零元素用i记行号用一维数组元素A[i]记第i行非零元个数(为方便输出设元素是整数)
int MatrixNum(Olink Hm)//输出由Hm指向的十字链表中每一行的非零元素个数
{Olink rch=Hm>uvalnext p;
int A[]; i=;//数组A记各行非零元个数i记行号
while(rch!=Hm)//循环完各行列表头
{p=rch>right; num=; //p是稀疏矩阵行内工作指针num记该行非零个数
while(p!=rch)//完成行内非零元的查找
{printf(M[%d][%d]=%dp>rowp>colp>uvale);
num++;p=p>right; printf(\n);//指针后移 }
A[i++]=num;//存该行非零元个数
rch=rch>uvalnext;//移到下一行列表头
}
num=
for(j=;j<i;j++)//输出各行非零元个数
{num+=A[j]; printf(第%d行非零元个数为%d\njA[j]); }
return(num);//稀疏矩阵非零元个数
}算法结束
[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []