<?xml version="1.0" encoding="GBK" ?>
<rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dcterms="http://purl.org/dc/terms/">
 <channel>
  	  <title><![CDATA[阿巴睇的博客]]></title>
	  <link>http://cgbluesky.blog.163.com</link>
	  <description><![CDATA[C#技术 人生一年又一年,只要每年都有所积累,有所成长,都有那么一次自己认为满意的花开时刻就好。即使一时不顺,也要敞开胸怀。生命的荣枯并不是简单的重复,一时的得失不是成败的尺度。花开不是荣耀,而是一个美丽的结束,花谢也不是耻辱,而是一个低调的开始。
]]></description>
	  <language>zh-CN</language>
	  <pubDate>Sun, 17 Aug 2008 00:16:50 +0800</pubDate>
	  <lastBuildDate>Sun, 17 Aug 2008 00:16:50 +0800</lastBuildDate>
	  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
	  <generator><![CDATA[NetEase Space]]></generator>
	  <managingEditor><![CDATA[cgbluesky]]></managingEditor>
	  <webMaster><![CDATA[阿巴睇]]></webMaster>
		  <ttl>120</ttl>
	  <image>
	  	<title><![CDATA[阿巴睇的博客]]></title>
	  	<url>http://cgbluesky.blog.163.com/style/common/user_default.gif</url>
	  	<link>http://cgbluesky.blog.163.com</link>
	  </image>
  <item>
  	<title><![CDATA[C#与数据结构--图的遍历]]></title>	
    <link>http://cgbluesky.blog.163.com/blog/static/241235582008561245867</link>
    <description><![CDATA[<div><H2 style="MARGIN: 13pt 0cm"><SPAN lang=EN-US style="mso-no-proof: yes">8.2 </SPAN><SPAN style="FONT-FAMILY: 黑体; mso-no-proof: yes; mso-ascii-font-family: Arial">图的存储结构</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"></SPAN></H2>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">图的存储结构除了要存储图中各个顶点的本身的信息外，同时还要存储顶点与顶点之间的所有关系（边的信息），因此，图的结构比较复杂，很难以数据元素在存储区中的物理位置来表示元素之间的关系，但也正是由于其任意的特性，故物理表示方法很多。常用的图的存储结构有邻接矩阵、邻接表、十字链表和邻接多重表。</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"></SPAN></P>
<H3 style="MARGIN: 13pt 0cm"><FONT size=5><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">8.2.1<SPAN style="mso-spacerun: yes">&nbsp; </SPAN></FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">邻接矩阵表示法</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"></SPAN></FONT></H3>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对于一个具有</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">n</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">个顶点的图，可以使用</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">n*n</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的矩阵（二维数组）来表示它们间的邻接关系。图</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">8.10</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和图</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">8.11</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中，矩阵</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">A(i</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">j)=1</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">表示图中存在一条边</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">(V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">i</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">j</SPAN></SUB><SPAN lang=EN-US style="mso-no-proof: yes">)</SPAN></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，而</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">A(i</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">j)=0</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">表示图中不存在边</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">(V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">i</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">j</SPAN></SUB><SPAN lang=EN-US style="mso-no-proof: yes">)</SPAN></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。实际编程时，当图为不带权图时，可以在二维数组中存放</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">bool</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">值，</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">A(i</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">j)=true</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">表示存在边</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">(V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">i</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">j</SPAN></SUB><SPAN lang=EN-US style="mso-no-proof: yes">)</SPAN></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">A(i</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">j)=false</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">表示不存在边</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">(V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">i</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">j</SPAN></SUB><SPAN lang=EN-US style="mso-no-proof: yes">)</SPAN></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">；当图带权值时，则可以直接在二维数组中存放权值，</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">A(i</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">j)=null</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">表示不存在边</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">(V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">i</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">j</SPAN></SUB><SPAN lang=EN-US style="mso-no-proof: yes">)</SPAN></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。</SPAN></P><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"></SPAN>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN lang=EN-US style="mso-no-proof: yes"><A href="http://img.blog.163.com/photo/nmPAJHgKCpxWkGKR16SnOw==/883831426872067945.jpg" target=_blank><IMG src="http://img.blog.163.com/photo/nmPAJHgKCpxWkGKR16SnOw==/883831426872067945.jpg"></A></SPAN></P><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face=宋体>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">图</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">8.10</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所示的是无向图的邻接矩阵表示法，可以观察到，矩阵延对角线对称，即</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">A(i</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">j)= A(j</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">i)</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。无向图邻接矩阵的第</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">i</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">行或第</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">i</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">列非零元素的个数其实就是第</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">i</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">个顶点的度。这表示无向图邻接矩阵存在一定的数据冗余。</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">图</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">8.11</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所示的是有向图邻接矩阵表示法，矩阵并不延对角线对称，</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">A(i</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">j)=1</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">表示顶点</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">i</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">邻接到顶点</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">j</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">；</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">A(j</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">i)=1</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">则表示顶点</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">i</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">邻接自顶点</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">j</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。两者并不象无向图邻接矩阵那样表示相同的意思。有向图邻接矩阵的第</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">i</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">行非零元素的个数其实就是第</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">i</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">个顶点的出度，而第</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">i</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">列非零元素的个数是第</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">i</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">个顶点的入度，即第</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">i</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">个顶点的度是第</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">i</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">行和第</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">i</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">列非零元素个数之和。</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">由于存在</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">n</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">个顶点的图需要</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">n</SPAN><SUP><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">2</SPAN></SUP></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt; mso-hansi-font-family: 'Times New Roman'">个数组元素进行存储，</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">当图为稀疏图时，使用邻接矩阵存储方法将出现大量零元素，照成极大地空间浪费，这时应该使用邻接表表示法存储图中的数据。</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"></SPAN></P>
<H3 style="MARGIN: 13pt 0cm"><FONT size=5><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">8.2.2 </FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">邻接表表示法</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"></SPAN></FONT></H3>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">图的邻接矩阵存储方法跟树的孩子链表示法相类似，是一种顺序分配和链式分配相结合的存储结构。邻接表由表头结点和表结点两部分组成，其中图中每个顶点均对应一个存储在数组中的表头结点。如这个表头结点所对应的顶点存在相邻顶点，则把相邻顶点依次存放于表头结点所指向的单向链表中。如图</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">8.12</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所示，表结点存放的是邻接顶点在数组中的索引。对于无向图来说，使用邻接表进行存储也会出现数据冗余，表头结点</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">A</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所指链表中存在一个指向</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">C</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的表结点的同时，表头结点</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">C</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所指链表也会存在一个指向</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">A</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的表结点。</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><A href="http://img.blog.163.com/photo/rZtBzPH2oao6oc48VSNQdQ==/566327653142318394.jpg" target=_blank><IMG src="http://img.blog.163.com/photo/rZtBzPH2oao6oc48VSNQdQ==/566327653142318394.jpg"></A></SPAN></P><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">有向图的邻接表有出边表和入边表（又称逆邻接表）之分。出边表的表结点存放的是从表头结点出发的有向边所指的尾顶点；入边表的表结点存放的则是指向表头结点的某个头顶点。如图</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">8.13</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所示，图</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">(b)</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">(c)</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">分别为有向图</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">(a)</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的出边表和入边表。</SPAN></P><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"></SPAN>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN lang=EN-US style="mso-no-proof: yes"><A href="http://img.blog.163.com/photo/WciqOLVWd3SNBlWkG8omlA==/3730387866346859417.jpg" target=_blank><IMG src="http://img.blog.163.com/photo/WciqOLVWd3SNBlWkG8omlA==/3730387866346859417.jpg"></A></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">以上所讨论的邻接表所表示的都是不带权的图，如果要表示带权图，可以在表结点中增加一个存放权的字段，其效果如图</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">8.14</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所示。</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN lang=EN-US style="mso-no-proof: yes"><A href="http://img.blog.163.com/photo/4IXTAwGWz3aS3QgfZu6zrw==/566327653142318402.jpg" target=_blank><IMG src="http://img.blog.163.com/photo/4IXTAwGWz3aS3QgfZu6zrw==/566327653142318402.jpg"></A></SPAN></P><SPAN lang=EN-US style="mso-no-proof: yes">
<P style="MARGIN: 0cm 22.9pt 0pt 27pt; mso-para-margin-top: 0cm; mso-para-margin-right: 2.18gd; mso-para-margin-bottom: .0001pt; mso-para-margin-left: 2.57gd"><SPAN style="FONT-FAMILY: 楷体_GB2312">【注意】：观察图<SPAN lang=EN-US>8.14</SPAN>可以发现，当删除存储表头结点的数组中的某一元素，有可能使部分表头结点索引号的改变，从而导致大面积修改表结点的情况发生。可以在表结点中直接存放指向表头结点的指针以解决这个问题（在链表中存放类实例即是存放指针，但必须要保证表头结点是类而不是结构体）。在实际创建邻接表时，甚至可以使用链表代替数组存放表头结点或使用顺序表存代替链表存放表结点。对所学的数据结构知识应当根据实际情况及所使用语言的特点灵活应用，切不可生搬硬套。<SPAN lang=EN-US></SPAN></SPAN></P>
<P style="MARGIN: 0cm 22.9pt 0pt 0cm; mso-para-margin-right: 2.18gd"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">【例</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">8-1<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>AdjacencyList.cs</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">】图的邻接表存储结构</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">1<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>&65279;using System;</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">2<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>using System.Collections.Generic;</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">3<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>public class AdjacencyList&lt;T&gt;</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">4<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>{</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">5<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>List&lt;Vertex&lt;T&gt;&gt; items; //</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">图的顶点集合</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">6<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>public AdjacencyList() : this(10) { } //</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">构造方法</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">7<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>public AdjacencyList(int capacity) //</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指定容量的构造方法</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">8<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">9<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>items = new List&lt;Vertex&lt;T&gt;&gt;(capacity);</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">10<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">11<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>public void AddVertex(T item) //</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">添加一个顶点</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">12<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>//</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">不允许插入重复值</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">13<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>if (Contains(item))</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">14<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">15<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>throw new ArgumentException("</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">插入了重复顶点！</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">");</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">16<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">17<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>items.Add(new Vertex&lt;T&gt;(item));</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">18<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">19<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>public void AddEdge(T from, T to) //</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">添加无向边</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">20<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">21<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Vertex&lt;T&gt; fromVer = Find(from); //</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">找到起始顶点</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">22<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>if (fromVer == null)</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">23<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">24<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>throw new ArgumentException("</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">头顶点并不存在！</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">");</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">25<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">26<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Vertex&lt;T&gt; toVer = Find(to); //</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">找到结束顶点</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">27<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;</SPAN>if (toVer == null)</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">28<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">29<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>throw new ArgumentException("</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">尾顶点并不存在！</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">");</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">30<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">31<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>//</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">无向边的两个顶点都需记录边信息</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">32<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>AddDirectedEdge(fromVer, toVer);</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">33<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>AddDirectedEdge(toVer, fromVer);</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">34<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">35<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>public bool Contains(T item) //</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">查找图中是否包含某项</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">36<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">37<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>foreach (Vertex&lt;T&gt; v in items)</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">38<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">39<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>if (v.data.Equals(item))</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">40<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">41<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>return true;</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">42<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">43<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">44<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>return false;</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">45<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">46<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>private Vertex&lt;T&gt; Find(T item) //</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">查找指定项并返回</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">47<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">48<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>foreach (Vertex&lt;T&gt; v in items)</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">49<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">50<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>if (v.data.Equals(item))</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">51<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">52<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>return v;</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">53<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">54<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">55<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>return null;</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">56<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">57<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>//</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">添加有向边</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">58<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>private void AddDirectedEdge(Vertex&lt;T&gt; fromVer, Vertex&lt;T&gt; toVer)</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">59<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">60<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>if (fromVer.firstEdge == null) //</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">无邻接点时</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">61<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">62<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>fromVer.firstEdge = new Node(toVer);</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">63<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">64<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>else</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">65<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">66<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Node tmp, node = fromVer.firstEdge;</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">67<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>do</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">68<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>//</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">检查是否添加了重复边</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">69<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>if (node.adjvex.data.Equals(toVer.data))</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">70<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">71<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>throw new ArgumentException("</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">添加了重复的边！</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">");</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">72<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">73<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>tmp = node;</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">74<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>node = node.next;</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">75<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>} while (node != null);</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">76<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>tmp.next = new Node(toVer); //</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">添加到链表未尾</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">77<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">78<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">79<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>public override string ToString() //</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">仅用于测试</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">80<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>//</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">打印每个节点和它的邻接点</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">81<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>string s = string.Empty;</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">82<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>foreach (Vertex&lt;T&gt; v in items)</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">83<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">84<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>s += v.data.ToString() + ":";</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">85<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>if (v.firstEdge != null)</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">86<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">87<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>Node tmp = v.firstEdge;</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">88<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>while (tmp != null)</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">89<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">90<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>s += tmp.adjvex.data.ToString();</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">91<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>tmp = tmp.next;</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">92<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">93<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">94<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>s += "\r\n";</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">95<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">96<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>return s;</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">97<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">98<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>//</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">嵌套类，表示链表中的表结点</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">99<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>public class Node</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">100<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">101<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>public Vertex&lt;T&gt; adjvex; //</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">邻接点域</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">102<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>public Node next; //</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">下一个邻接点指针域</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">103<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>public Node(Vertex&lt;T&gt; value)</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">104<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">105<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>adjvex = value;</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">106<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">107<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">108<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>//</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">嵌套类，表示存放于数组中的表头结点</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">109<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>public class Vertex&lt;TValue&gt;</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">110<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">111<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>public TValue data; //</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">数据</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">112<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>public Node firstEdge; //</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">邻接点链表头指针</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">113<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>public Boolean visited; //</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">访问标志</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">,</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">遍历时使用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">114<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>public Vertex(TValue value) //</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">构造方法</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">115<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">116<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>data = value;</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">117<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">118<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">119 }</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">AdjacencyList&lt;T&gt;</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类使用泛型实现了图的邻接表存储结构。它包含两个内部类，</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">Vertex&lt;Tvalue&gt;</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类（</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">10</FONT></SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-no-proof: yes">9</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes">～<SPAN lang=EN-US>118</SPAN>行代码</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）用于表示一个表头结点，</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">Node</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类（</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">9</FONT></SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-no-proof: yes">9</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes">～<SPAN lang=EN-US>107</SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）则用于表示表结点，其中存放着邻接点信息，用来表示表头结点的某条边。多个</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">Node</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">用</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">next</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">指针相连形成一个单链表，表头指针为</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">Vertex</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类的</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">firstEdge</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">成员，表头结点所代表的顶点的所有边的信息均包含在链表内，其结构如图</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">8.12</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所示。所不同之处在于：</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo1; tab-stops: list 42.0pt"><SPAN lang=EN-US style="FONT-FAMILY: Wingdings; mso-no-proof: yes; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings"><SPAN style="mso-list: Ignore">l<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">Vertex</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类中包含了一个</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">visited</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">成员，它的作用是在图遍历时标识当前节点是否被访问过，这一点在稍后会讲到。</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo1; tab-stops: list 42.0pt"><SPAN lang=EN-US style="FONT-FAMILY: Wingdings; mso-no-proof: yes; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings"><SPAN style="mso-list: Ignore">l<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">邻接点指针域</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">adjvex</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">直接指向某个表头结点，而不是表头结点在数组中的索引。</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">AdjacencyList&lt;T&gt;</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类中使用了一个泛型</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">List</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">代替数组来保存表头结点信息（第</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">5</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">行代码），从而不再考虑数组存储空间不够的情况发生，简化了操作。</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">由于一条无向边的信息需要在边的两个顶点分别存储信息，即添加两个有向边，所以</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">5</FONT></SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-no-proof: yes">8</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes">～<SPAN lang=EN-US>78</SPAN>行代码的私有方法<SPAN lang=EN-US>AddDirectedEdge()</SPAN>方法用于添加一个有向边。新的邻接点信息即可以添加到链表的头部也可以添加到尾部，添加到链表头部可以简化操作，但考虑到要检查是否添加了重复边，需要遍历整个链表，所以最终把邻接点信息添加到链表尾部。<SPAN lang=EN-US></SPAN></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">【例</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">8-1<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Demo8-1.cs</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">】图的邻接表存储结构测试</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">1<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>&65279;using System;</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">2<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>class Demo8_1</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">3<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>{</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">4<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>static void Main(string[] args)</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">5<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">6<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>AdjacencyList&lt;char&gt; a = new AdjacencyList&lt;char&gt;();</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">7<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>//</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">添加顶点</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">8<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>a.AddVertex('A');</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">9<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>a.AddVertex('B');</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">10<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>a.AddVertex('C');</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">11<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>a.AddVertex('D');</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">12<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>//</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">添加边</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">13<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>a.AddEdge('A', 'B');</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">14<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>a.AddEdge('A', 'C');</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">15<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>a.AddEdge('A', 'D');</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">16<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>a.AddEdge('B', 'D');</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">17<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Console.WriteLine(a.ToString());</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">18<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">19 }</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">运行结果：</SPAN></P><SPAN style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">A</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">：</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">BCD</FONT></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">B</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">：</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">AD</FONT></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">C</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">：</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">A</FONT></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">D</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">：</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">AB</FONT></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">本例存储的表如图</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">8.12</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所示，结果中，冒号前面的是表头结点，冒号后面的是链表中的表结点。</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"></SPAN></P>
<H2 style="MARGIN: 13pt 0cm"><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face=Arial>8.3 </FONT></SPAN><SPAN style="FONT-FAMILY: 黑体; mso-no-proof: yes; mso-ascii-font-family: Arial">图的遍历</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"></SPAN></H2>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和树的遍历类似，在此，我们希望从图中某一顶点出发访遍图中其余顶点，且使每一个顶点仅被访问一次，这一过程就叫做图的遍历</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">(TraversingGraph)</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。如果只访问图的顶点而不关注边的信息，那么图的遍历十分简单，使用一个</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">foreach</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">语句遍历存放顶点信息的数组即可。但如果为了实现特定算法，就需要根据边的信息按照一定顺序进行遍历。图的遍历算法是求解图的连通性问题、拓扑排序和求关键路径等算法的基础。</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">图的遍历要比树的遍历复杂得多，由于图的任一顶点都可能和其余顶点相邻接，故在访问了某顶点之后，可能顺着某条边又访问到了已访问过的顶点，因此，在图的遍历过程中，必须记下每个访问过的顶点，以免同一个顶点被访问多次。为此给顶点附设访问标志</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">visited</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，其初值为</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">false</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，一旦某个顶点被访问，则其</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">visited</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">标志置为</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">true</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">图的遍历方法有两种：一种是深度优先搜索遍历（</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">Depth-First Search </FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">简称</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">DFS</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）；另一种是广度优先搜索遍历（</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">Breadth_First Search </FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">简称</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">BFS</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）。</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"></SPAN></P>
<H3 style="MARGIN: 13pt 0cm"><FONT size=5><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">8.3.1<SPAN style="mso-spacerun: yes">&nbsp; </SPAN></FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">深度优先搜索遍历</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"></SPAN></FONT></H3>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">图的深度优先搜索遍历类似于二叉树的深度优先搜索遍历。其基本思想如下：假定以图中某个顶点</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">i</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">为出发点，首先访问出发点，然后选择一个</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">i</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的未访问过的邻接点</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">j</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，以</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">j</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">为新的出发点继续进行深度优先搜索，直至图中所有顶点都被访问过。显然，这是一个递归的搜索过程。</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">现以图</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">8.15</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">为例说明深度优先搜索过程。假定</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">1</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是出发点，首先访问</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">1</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。因</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">1</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">有两个邻接点</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">2</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">3</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">均末被访问过，可以选择</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">2</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">作为新的出发点，访问</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">2</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">之后，再找</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">2</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的末访问过的邻接点。同</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">2</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">邻接的有</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">1</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">4</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">5</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，其中</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">1</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">已被访问过，而</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">4</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">5</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">尚未被访问过，可以选择</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">4</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">作为新的出发点。重复上述搜索过程，继续依次访问</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">8</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">5</SPAN></SUB><SPAN lang=EN-US style="mso-no-proof: yes"> </SPAN></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。访问</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">5</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">之后，由于与</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">5</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">相邻的顶点均已被访问过，搜索退回到</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">8</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，访问</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">8</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的另一个邻接点</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">6</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。接下来依次访问</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">3</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">7</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，最后得到的的顶点的访问序列为：</SPAN><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-no-proof: yes">V</SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">1</SPAN></SUB><SPAN lang=EN-US style="mso-no-proof: yes"> </SPAN></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">→</SPAN><FONT face="Times New Roman"><SPAN style="mso-no-proof: yes"> <SPAN lang=EN-US>V</SPAN></SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">2</SPAN></SUB><SPAN lang=EN-US style="mso-no-proof: yes"> </SPAN></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">→</SPAN><FONT face="Times New Roman"><SPAN style="mso-no-proof: yes"> <SPAN lang=EN-US>V</SPAN></SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">4</SPAN></SUB><SPAN lang=EN-US style="mso-no-proof: yes"> </SPAN></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">→</SPAN><FONT face="Times New Roman"><SPAN style="mso-no-proof: yes"> <SPAN lang=EN-US>V</SPAN></SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">8</SPAN></SUB><SPAN lang=EN-US style="mso-no-proof: yes"> </SPAN></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">→</SPAN><FONT face="Times New Roman"><SPAN style="mso-no-proof: yes"> <SPAN lang=EN-US>V</SPAN></SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">5</SPAN></SUB><SPAN lang=EN-US style="mso-no-proof: yes"> </SPAN></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">→</SPAN><FONT face="Times New Roman"><SPAN style="mso-no-proof: yes"> <SPAN lang=EN-US>V</SPAN></SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">6</SPAN></SUB><SPAN lang=EN-US style="mso-no-proof: yes"> </SPAN></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">→</SPAN><FONT face="Times New Roman"><SPAN style="mso-no-proof: yes"> <SPAN lang=EN-US>V</SPAN></SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">3</SPAN></SUB><SPAN lang=EN-US style="mso-no-proof: yes"> </SPAN></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">→</SPAN><FONT face="Times New Roman"><SPAN style="mso-no-proof: yes"> <SPAN lang=EN-US>V</SPAN></SPAN><SUB><SPAN lang=EN-US style="mso-no-proof: yes; mso-bidi-font-size: 10.5pt">7</SPAN></SUB></FONT><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><A href="http://img.blog.163.com/photo/Mk0vNPsvT5w6Jg5EmyNDEA==/566327653142318403.jpg" target=_blank><IMG src="http://img.blog.163.com/photo/Mk0vNPsvT5w6Jg5EmyNDEA==/566327653142318403.jpg"></A></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">下面根据上一节创建的邻接表存储结构添加深度优先搜索遍历代码。</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"></SPAN></P>
<P style="MARGIN: 0cm 22.9pt 0pt 0cm; mso-para-margin-right: 2.18gd"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">【例</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">8-2<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>DFSTraverse.cs</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">】深度优先搜索遍历</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">打开</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">【例</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">8-1<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>AdjacencyList.cs</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">】，<SPAN style="mso-no-proof: yes">在</SPAN></SPAN><SPAN lang=EN-US style="mso-no-proof: yes"><FONT face="Times New Roman">AdjacencyList&lt;T&gt;</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-no-proof: yes; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类中添加以下代码后，将文件另存为</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">DFSTraverse.cs</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。</SPAN><SPAN lang=EN-US style="mso-no-proof: yes"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">35<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>public void DFSTraverse() //</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">深度优先遍历</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">36<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">37<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>InitVisited(); //</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">将</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">visited</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">标志全部置为</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">false</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">38<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>DFS(items[0]); //</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 新宋体; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">从第一个顶点开始遍历</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt"></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">39<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 12pt; TEXT-ALIGN: left; mso-line-height-rule: exactly; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: #993366; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-fareast-font-family: 新宋体; mso-font-kerning: 0pt">40<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>private void DFS(Vertex&lt;T&gt; v) //</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: #993366; FO