[題目分析]設稀疏矩陣是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);//稀疏矩陣非零元個數
}算法結束
[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
From:http://tw.wingwit.com/Article/program/sjjg/201311/23023.html