📄 text4-25.htm
字号:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#FFFFFF" link="#0000FF" vlink="#3399FF" alink="#FF0066">
<div id="Layer1" style="position:absolute; width:711px; height:21px; z-index:1; top: 10px; background-color: #CCCCCC; layer-background-color: #CCCCCC; border: 1px none #000000; left: 26px"><b>|</b><font face="宋体" size="2"><a href="../text1/text1-0.htm">第一章</a></font><b>|</b><font face="宋体" size="2"><a href="../text2/text2-0.htm">第二章</a></font><b>|</b><font face="宋体" size="2"><a href="../text3/text3-0.htm">第三章</a></font><b>|</b><font face="宋体" size="2">第四章</font><b>|</b><font face="宋体" size="2"><a href="../text5/text5-0.htm">第五章</a></font><b>|</b><font face="宋体" size="2"><a href="../text6/text6-0.htm">第六章</a></font><b>|</b><font face="宋体" size="2"><a href="../text7/text7-0.htm">第七章</a></font><b>|</b><font face="宋体" size="2"><a href="../text8/text8-0.htm">第八章</a></font><b>|</b><font face="宋体" size="2"><a href="../text9/text9-0.htm">第九章</a></font><b>|</b><font face="宋体" size="2"><a href="../text10/text10-0.htm">第十章</a></font><b>|</b><font size="2" face="宋体"><a href="../textA/textA-0.htm">算法分析</a><b><font color="#000000">|</font></b>
</font></div>
<pre align="left"><font face="Arial, Helvetica, sans-serif" size="4" color="#000000"><b>
<font color="#0033CC">Program</font> :<font color="#FF0000"> Read in a sparse matrix</font>
matrix_pointer<font color="#FF0000"> mread</font>(void)
{ <i><font size="3" color="#FF0099">/* read in a matrix and set up its linked representation. An
auxiliary global array hdnode is used */</font></i>
int num_rows, num_cols, num_terms, num_heads, i;
int col, col, value, last, node;
printf("Enter the number of rows, columns and number of
nonzero terms: ");
scanf("%d%d%d',&num_rows,&num_cols,&num_terms);
num_heads = (num_cols > num_rows) ? num_cols :
num_rows;
<i><font size="3" color="#FF0099"> /* set up head node for the list of head nodes */</font></i>
node = new_node(); node->tag = entry;
node->u.entry.row = num_rows;
node->u.entry.col = num_cols;</b></font></pre>
<table width="744" cellspacing="0">
<tr>
<td rowspan="5" width="550">
<pre><font face="Arial, Helvetica, sans-serif" size="4" color="#000000"><b>if ( !num_heads ) node->right = node;
else {<i><font size="3" color="#FF0099"> /* initialize the head nods */</font></i>
for ( i = 0; i<num_heads; i++ ) {
temp = new_node();
hdnode[i] = temp; hdnode[i]->tag = head;
hdnode[i]->right = temp;
hdnode[i]->u.next = temp;
}
current_row = 0;
last = hdnode[0];<i><font size="3" color="#FF0099"> /* last node in current row */</font></i>
for ( i = 0; i < num_terms; i++ ) {
printf("Enter row, column and value: ");
scanf("%d%d%d",&row,&col,&value);
if ( row > current_row ) {
<i><font size="3" color="#FF0099"> /* close current row */</font></i>
last->right = hdnode[current_row];
current_row = row; last = hdnode[row];
}
temp = new_node();
temp->tag = entry; temp->u.entry.row = row;
temp->u.entry.col = col;
temp->u.entry.value = value;
last->right = temp; <i><font size="3" color="#FF0099">/* link into row list */</font></i>
last = temp;
<i><font size="3" color="#FF0099">/* link into column list */</font></i>
hdnode[col]->u.next->down = temp; <font size="2" color="#990000">(1)</font>
hdnode[col]->u.next = temp; <font size="2" color="#990000">(2)</font>
}
<i><font size="3" color="#FF0099">/* close last row */</font></i>
last->right = hdnode[current_row]; <font size="2" color="#990000">(3)</font>
<i><font size="3" color="#FF0099"> /* close all column lists */</font></i>
for ( i=0; i<num_cols; i++ )
hdnode[i]->u.next->down = hdnode[i]; <font size="2" color="#990000">(4)</font>
<i><font size="3" color="#FF0099"> /* link all head nodes together */</font></i>
for ( i=0; i<num_heads-1; i++ )
hdnode[i]->u.next = hdnode[i+1];
hdnode[num_heads-1]->u.next = node;
node->right = hdnode[0];
}
return node;
}
</b></font></pre>
</td>
<td width="178" height="287"><img src="IMAGE/4-7-0.gif" width="192" height="82" align="bottom"></td>
</tr>
<tr>
<td width="178" height="75"> </td>
</tr>
<tr>
<td width="178" height="246" align="center" valign="middle"> <img src="IMAGE/4-7-1.gif" width="155" height="84"></td>
</tr>
<tr>
<td width="178" height="357"><img src="IMAGE/4-7-2.gif" width="201" height="266"></td>
</tr>
<tr>
<td width="178"> </td>
</tr>
</table>
<pre align="left"> </pre>
<table width="731" cellspacing="0" cellpadding="0">
<tr>
<td width="327"> </td>
<td width="271"><a href="../index.htm"><img width="60" height="25" usemap="#MapMap4" border="0" src="../../images/home.gif"></a><a href="../index.htm"><map name="MapMap4"><area shape="rect" coords="42,-34,88,-15" href="text0.htm"><area shape="rect" coords="4,4,55,23" href="text4-index.htm"></map></a></td>
<td width="131"><font face="楷体_GB2312" size="2"><b><a href="text4-24.htm">上一页</a>
<a href="text4-26.htm">下一页</a> </b></font></td>
</tr>
</table>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -