<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://metabolomics.jp/mediawiki/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://metabolomics.jp/mediawiki/index.php?action=history&amp;feed=atom&amp;title=Aritalab%3ALecture%2FProgramming%2FJava%2FGraph</id>
		<title>Aritalab:Lecture/Programming/Java/Graph - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://metabolomics.jp/mediawiki/index.php?action=history&amp;feed=atom&amp;title=Aritalab%3ALecture%2FProgramming%2FJava%2FGraph"/>
		<link rel="alternate" type="text/html" href="http://metabolomics.jp/mediawiki/index.php?title=Aritalab:Lecture/Programming/Java/Graph&amp;action=history"/>
		<updated>2026-06-16T12:49:32Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.19.1</generator>

	<entry>
		<id>http://metabolomics.jp/mediawiki/index.php?title=Aritalab:Lecture/Programming/Java/Graph&amp;diff=255482&amp;oldid=prev</id>
		<title>Adm at 16:20, 1 June 2011</title>
		<link rel="alternate" type="text/html" href="http://metabolomics.jp/mediawiki/index.php?title=Aritalab:Lecture/Programming/Java/Graph&amp;diff=255482&amp;oldid=prev"/>
				<updated>2011-06-01T16:20:23Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
			&lt;tr valign='top'&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 16:20, 1 June 2011&lt;/td&gt;
			&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 312:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 312:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; }&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; }&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;==ヒント==&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;;頂点や辺のデータにアクセスするにはメソッドを使う&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;汎用性のために頂点や辺が持つデータの型はObjectにしておきます。そうすると、実際に整数型が入っているときは以下のように使うことになります。&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;:Integer i = (Integer)edge.target.data;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;しかしこれでは、クラスの中身が丸見えで、後日リファクタリング等を行なう際の妨げにもなります。そのため各フィールドにアクセスするのにメソッドを使います。&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;:Integer i = (Integer)edge.target().getData();&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;こうしておくと、後日たとえばtargetというフィールド名をtarget2変更したときに、コード中のtarget文字列を変更する必要はなくなります。&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;:Node target() { return target2; }&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;というようにメソッドだけ変更すれば済むからです。&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;;整数値と文字列の変換&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Javaからユーザ入力された値を整数や実数として扱いたい場合が多々あります。スペース区切りの数値データを使う方法は以下のとおりです。&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;:String input = &amp;quot;ここにデータが入る&amp;quot;;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;:String[] data = input.split();&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;:for (int i=0; i &amp;lt; data.length; i+ +)&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;:&amp;#160; { int value = Integer.parseInt(data[i]); }&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;実数なら、Double.parseDouble(文字列); という関数があります。Boolean等も同じです。&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;;データの隠蔽を心がける&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Javaでコードを書くときは、そのコードを「ライブラリとして」後日使うことを意識すると便利です。例えば、グラフ構造のコードの中に、グラフ構造向けのアルゴリズムのコードが含まれることは望ましくありません。アルゴリズムはグラフ構造の外側からアクセスすべきです。&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;;グラフ構造作成の好ましくない例&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;:LinkedList edges = new LinkedList();&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;:LinkedList nodes = new LinkedList();&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;:Graph G = new Graph(nodes, edges);&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;こうしてしまうと、Graphクラス中で利用するデータ構造がLinkedListクラスであることがわかりますし、中身の入った別のLinkedListを渡すことも出来てしまいます。上記の実装は例えば以下のようにすべきです。&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;:Class Graph {&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;: LinkedList nodes, edges;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;:&amp;#160; Graph() { nodes = new LinkedList(); edges = new LinkedList(); }&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;:}&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;こうしてGraphクラスを作っていくと、例えばダイクストラ法で「頂点をvisitしたかどうか」をどう判定するか悩むことになります。Graphが使うNodeクラス中に、boolean visited; というフィールドを設けることは簡単ですが、これは他のほとんどの用途において無駄なフィールドになってしまいます。そのために、外部から全頂点や全辺の配列を得るメソッドを用意してあるのです。&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;:Class Graph {&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;:&amp;#160; Node[] allNodes() {&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;:&amp;#160; Node[] ret = new Node[numberOfNodes()];&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;:&amp;#160; int i=0;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;:&amp;#160; for(Node n = nodes.head(); n != null; n = n.next()) ret[i+ +] = n;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;:&amp;#160; return ret;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;:&amp;#160; }&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;:}&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;この戻り値は配列である必要はなく、ハッシュテーブルや双方向リストのままでもOKです。ただし、&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;:LinkedList allNodes() { return nodes; }&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;という実装は好ましくありません。これはGraphクラスの中身をそのまま渡してしまうため、せっかく隠蔽している意味がなくなってしまいます。&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Adm</name></author>	</entry>

	<entry>
		<id>http://metabolomics.jp/mediawiki/index.php?title=Aritalab:Lecture/Programming/Java/Graph&amp;diff=255481&amp;oldid=prev</id>
		<title>Adm at 01:07, 28 April 2011</title>
		<link rel="alternate" type="text/html" href="http://metabolomics.jp/mediawiki/index.php?title=Aritalab:Lecture/Programming/Java/Graph&amp;diff=255481&amp;oldid=prev"/>
				<updated>2011-04-28T01:07:31Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
			&lt;tr valign='top'&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 01:07, 28 April 2011&lt;/td&gt;
			&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 3:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 3:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;頂点の集合 ''V'' と、常に2頂点を結ぶ辺の集合 ''E'' の組をグラフ G(''V'', ''E'') と書きます。&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;頂点の集合 ''V'' と、常に2頂点を結ぶ辺の集合 ''E'' の組をグラフ G(''V'', ''E'') と書きます。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;頂点には任意の数の辺が接続しうるので、グラフ構造をプログラミング言語で実現するには二重リスト構造を使います。&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;頂点には任意の数の辺が接続しうるので、グラフ構造をプログラミング言語で実現するには二重リスト構造を使います。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;以下のプログラムのほかに&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;* [[Aritalab:Lecture/Programming/Java/Graph/Node|頂点の実装]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;* [[Aritalab:Lecture/Programming/Java/Graph/Edge|辺の実装]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;* [[Aritalab:Lecture/Programming/Java/Graph/LinkedList|リストの実装]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;* [[Aritalab:Lecture/Programming/Java/Graph/ListEntry|リストの実装2]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;ファイルを用います。&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Adm</name></author>	</entry>

	<entry>
		<id>http://metabolomics.jp/mediawiki/index.php?title=Aritalab:Lecture/Programming/Java/Graph&amp;diff=255480&amp;oldid=prev</id>
		<title>Adm at 00:52, 28 April 2011</title>
		<link rel="alternate" type="text/html" href="http://metabolomics.jp/mediawiki/index.php?title=Aritalab:Lecture/Programming/Java/Graph&amp;diff=255480&amp;oldid=prev"/>
				<updated>2011-04-28T00:52:13Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
			&lt;tr valign='top'&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 00:52, 28 April 2011&lt;/td&gt;
			&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 5:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 5:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;package alg.graph;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;public class Graph&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;public class Graph&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; {&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; {&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 14:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 12:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; &amp;#160; private int max_edge_id = 0;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; &amp;#160; private int max_edge_id = 0;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; &amp;#160; private &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;ListRep &lt;/del&gt;v_list = new &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;ListRep&lt;/del&gt;();&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; &amp;#160; private &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;LinkedList &lt;/ins&gt;v_list = new &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;LinkedList&lt;/ins&gt;();&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; &amp;#160; private &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;ListRep &lt;/del&gt;e_list = new &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;ListRep&lt;/del&gt;();&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; &amp;#160; private &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;LinkedList &lt;/ins&gt;e_list = new &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;LinkedList&lt;/ins&gt;();&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; &amp;#160; public Graph() {}&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; &amp;#160; public Graph() {}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Adm</name></author>	</entry>

	<entry>
		<id>http://metabolomics.jp/mediawiki/index.php?title=Aritalab:Lecture/Programming/Java/Graph&amp;diff=255479&amp;oldid=prev</id>
		<title>Adm: Created page with &quot;==グラフの構造==  頂点の集合 ''V'' と、常に2頂点を結ぶ辺の集合 ''E'' の組をグラフ G(''V'', ''E'') と書きます。 頂点には任意の数の辺...&quot;</title>
		<link rel="alternate" type="text/html" href="http://metabolomics.jp/mediawiki/index.php?title=Aritalab:Lecture/Programming/Java/Graph&amp;diff=255479&amp;oldid=prev"/>
				<updated>2011-04-28T00:44:27Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;==グラフの構造==  頂点の集合 &amp;#039;&amp;#039;V&amp;#039;&amp;#039; と、常に2頂点を結ぶ辺の集合 &amp;#039;&amp;#039;E&amp;#039;&amp;#039; の組をグラフ G(&amp;#039;&amp;#039;V&amp;#039;&amp;#039;, &amp;#039;&amp;#039;E&amp;#039;&amp;#039;) と書きます。 頂点には任意の数の辺...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==グラフの構造==&lt;br /&gt;
&lt;br /&gt;
頂点の集合 ''V'' と、常に2頂点を結ぶ辺の集合 ''E'' の組をグラフ G(''V'', ''E'') と書きます。&lt;br /&gt;
頂点には任意の数の辺が接続しうるので、グラフ構造をプログラミング言語で実現するには二重リスト構造を使います。&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
package alg.graph;&lt;br /&gt;
&lt;br /&gt;
public class Graph&lt;br /&gt;
  {&lt;br /&gt;
    private boolean directed = true;&lt;br /&gt;
&lt;br /&gt;
    private int max_node_id = 0;&lt;br /&gt;
    private int max_edge_id = 0;&lt;br /&gt;
&lt;br /&gt;
    private ListRep v_list = new ListRep();&lt;br /&gt;
    private ListRep e_list = new ListRep();&lt;br /&gt;
&lt;br /&gt;
    public Graph() {}&lt;br /&gt;
&lt;br /&gt;
    public void removeEdge(GraphEdge e)&lt;br /&gt;
      {&lt;br /&gt;
        GraphNode v = source(e);&lt;br /&gt;
        GraphNode w = target(e);&lt;br /&gt;
&lt;br /&gt;
        if (v.owner != this)&lt;br /&gt;
          throw new Exception(&amp;quot;removeEdge(e): e is not in G&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
        v.del_out_edge(e);&lt;br /&gt;
        w.del_in_edge(e);&lt;br /&gt;
&lt;br /&gt;
        e_list.remove(e);&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public void removeNode(GraphNode v)&lt;br /&gt;
      {&lt;br /&gt;
        if (v.owner != this)&lt;br /&gt;
          throw new Exception(&amp;quot;removeNode(v): v is not in G&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
        GraphEdge e;&lt;br /&gt;
        for (int i = 0; i &amp;lt; 2; i++)&lt;br /&gt;
          {&lt;br /&gt;
            e = v.first_inout_edge[i];&lt;br /&gt;
            while (e != null)&lt;br /&gt;
              {&lt;br /&gt;
                removeEdge(e);&lt;br /&gt;
                e = v.first_inout_edge[i];&lt;br /&gt;
              }&lt;br /&gt;
          }&lt;br /&gt;
&lt;br /&gt;
        v_list.remove(v);&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    private void del_all_edges()&lt;br /&gt;
      {&lt;br /&gt;
        e_list.clear();&lt;br /&gt;
        max_edge_id = 0;&lt;br /&gt;
&lt;br /&gt;
        for (GraphNode v = this.firstNode(); v != null; v = succNode(v))&lt;br /&gt;
          {&lt;br /&gt;
            for (int i = 0; i &amp;lt; 2; i++)&lt;br /&gt;
              {&lt;br /&gt;
                v.first_inout_edge[i] = null;&lt;br /&gt;
                v.last_inout_edge[i] = null;&lt;br /&gt;
                v.inout_deg[i] = 0;&lt;br /&gt;
              }&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public void clear()&lt;br /&gt;
      {&lt;br /&gt;
        del_all_edges();&lt;br /&gt;
        v_list.clear();&lt;br /&gt;
        max_node_id = 0;&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    // 頂点の作成&lt;br /&gt;
    private GraphNode createNode(NodeData nd)&lt;br /&gt;
      {&lt;br /&gt;
        GraphNode v = new GraphNode(nd);&lt;br /&gt;
        v.owner = this;&lt;br /&gt;
        v.v_id = ++max_node_id;&lt;br /&gt;
        this.v_list.append(v);&lt;br /&gt;
        return v;&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public GraphNode newNode()&lt;br /&gt;
      {&lt;br /&gt;
        return createNode(new NodeData());&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public GraphNode newNode(NodeData nd)&lt;br /&gt;
      {&lt;br /&gt;
        return createNode(nd);&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    private GraphEdge createEdge(GraphNode v, GraphNode w,&lt;br /&gt;
        EdgeData ed)&lt;br /&gt;
      {&lt;br /&gt;
        GraphEdge e;&lt;br /&gt;
&lt;br /&gt;
        if ((v.owner != this) || (w.owner != this))&lt;br /&gt;
          throw new Exception(&amp;quot;newEdge(v,w): v or w not in graph&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
        e = new GraphEdge(v, w, ed);&lt;br /&gt;
        e.e_id = ++max_edge_id;&lt;br /&gt;
        this.e_list.append(e);&lt;br /&gt;
        v.add_out_edge(e);&lt;br /&gt;
        w.add_in_edge(e);&lt;br /&gt;
&lt;br /&gt;
        return e;&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public GraphEdge newEdge(GraphNode v, GraphNode w,&lt;br /&gt;
        EdgeData ed)&lt;br /&gt;
      {&lt;br /&gt;
        return createEdge(v, w, ed);&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public GraphEdge newEdge(GraphNode v, GraphNode w)&lt;br /&gt;
      {&lt;br /&gt;
        return createEdge(v, w, new EdgeData());&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    // グラフを通して頂点や辺のデータを取得する&lt;br /&gt;
    public int index(GraphNode v)&lt;br /&gt;
      {&lt;br /&gt;
        return v.v_id;&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public int index(GraphEdge e)&lt;br /&gt;
      {&lt;br /&gt;
        return e.e_id;&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public int degree(GraphNode v)&lt;br /&gt;
      {&lt;br /&gt;
        return directed ? v.outdeg() : v.inoutdeg();&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public int indeg(GraphNode v)&lt;br /&gt;
      {&lt;br /&gt;
        return v.indeg();&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public int outdeg(GraphNode v)&lt;br /&gt;
      {&lt;br /&gt;
        return v.outdeg();&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public int numberOfNodes()&lt;br /&gt;
      {&lt;br /&gt;
        return v_list.size();&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public int numberOfEdges()&lt;br /&gt;
      {&lt;br /&gt;
        return e_list.size();&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public GraphNode source(GraphEdge e)&lt;br /&gt;
      {&lt;br /&gt;
        return e.source;&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public GraphNode target(GraphEdge e)&lt;br /&gt;
      {&lt;br /&gt;
        return e.target;&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public GraphNode opposite(GraphEdge e, GraphNode v)&lt;br /&gt;
      {&lt;br /&gt;
        return (v == source(e)) ? target(e) : source(e);&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public GraphNode firstNode()&lt;br /&gt;
      {&lt;br /&gt;
        return (GraphNode) v_list.head();&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public GraphNode lastNode()&lt;br /&gt;
      {&lt;br /&gt;
        return (GraphNode) v_list.tail();&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public GraphNode succNode(GraphNode v)&lt;br /&gt;
      {&lt;br /&gt;
        return (v != null) ? (GraphNode) v_list.Succ(v)&lt;br /&gt;
            : null;&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public GraphNode predNode(GraphNode v)&lt;br /&gt;
      {&lt;br /&gt;
        return (v != null) ? (GraphNode) v_list.Pred(v)&lt;br /&gt;
            : null;&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public GraphEdge firstEdge()&lt;br /&gt;
      {&lt;br /&gt;
        return (GraphEdge) e_list.head();&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public GraphEdge lastEdge()&lt;br /&gt;
      {&lt;br /&gt;
        return (GraphEdge) e_list.tail();&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public GraphEdge succEdge(GraphEdge e)&lt;br /&gt;
      {&lt;br /&gt;
        return (e != null) ? (GraphEdge) e_list.Succ(e)&lt;br /&gt;
            : null;&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public GraphEdge predEdge(GraphEdge e)&lt;br /&gt;
      {&lt;br /&gt;
        return (e != null) ? (GraphEdge) e_list.Pred(e)&lt;br /&gt;
            : null;&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public GraphEdge firstInEdge(GraphNode v)&lt;br /&gt;
      {&lt;br /&gt;
        return v.first_in_edge();&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public GraphEdge firstOutEdge(GraphNode v)&lt;br /&gt;
      {&lt;br /&gt;
        return v.first_out_edge();&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public GraphEdge succInEdge(GraphEdge e)&lt;br /&gt;
      {&lt;br /&gt;
        return e.succ_in_edge();&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public GraphEdge succOutEdge(GraphEdge e)&lt;br /&gt;
      {&lt;br /&gt;
        return e.succ_out_edge();&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public GraphEdge predInEdge(GraphEdge e)&lt;br /&gt;
      {&lt;br /&gt;
        return e.pred_in_edge();&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public GraphEdge predOutEdge(GraphEdge e)&lt;br /&gt;
      {&lt;br /&gt;
        return e.pred_out_edge();&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public boolean isDirected()&lt;br /&gt;
      {&lt;br /&gt;
        return directed;&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public void makeDirected()&lt;br /&gt;
      {&lt;br /&gt;
        directed = true;&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public void makeUndirected()&lt;br /&gt;
      {&lt;br /&gt;
        directed = false;&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public GraphNode[] adjNodes(GraphNode v)&lt;br /&gt;
      {&lt;br /&gt;
        GraphNode[] ret = new GraphNode[degree(v)];&lt;br /&gt;
        int pos = 0;&lt;br /&gt;
        for (GraphEdge e = firstOutEdge(v); e != null; e = succOutEdge(e))&lt;br /&gt;
          ret[pos++] = opposite(e, v);&lt;br /&gt;
        if (directed)&lt;br /&gt;
          return ret;&lt;br /&gt;
        for (GraphEdge e = firstInEdge(v); e != null; e = succInEdge(e))&lt;br /&gt;
          ret[pos++] = opposite(e, v);&lt;br /&gt;
        return ret;&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public GraphEdge[] adjEdges(GraphNode v)&lt;br /&gt;
      {&lt;br /&gt;
        GraphEdge[] ret = new GraphEdge[degree(v)];&lt;br /&gt;
        int pos = 0;&lt;br /&gt;
        for (GraphEdge e = firstOutEdge(v); e != null; e = succOutEdge(e))&lt;br /&gt;
          ret[pos++] = e;&lt;br /&gt;
        if (directed)&lt;br /&gt;
          return ret;&lt;br /&gt;
        for (GraphEdge e = firstInEdge(v); e != null; e = succInEdge(e))&lt;br /&gt;
          ret[pos++] = e;&lt;br /&gt;
        return ret;&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public GraphEdge[] allEdges()&lt;br /&gt;
      {&lt;br /&gt;
        GraphEdge[] ret = new GraphEdge[numberOfEdges()];&lt;br /&gt;
        int i = 0;&lt;br /&gt;
        for (GraphEdge e = firstEdge(); e != null; e = succEdge(e))&lt;br /&gt;
          ret[i++] = e;&lt;br /&gt;
        return ret;&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
    public GraphNode[] allNodes()&lt;br /&gt;
      {&lt;br /&gt;
        GraphNode[] ret = new GraphNode[numberOfNodes()];&lt;br /&gt;
        int i = 0;&lt;br /&gt;
        for (GraphNode v = firstNode(); v != null; v = succNode(v))&lt;br /&gt;
          ret[i++] = v;&lt;br /&gt;
        return ret;&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Adm</name></author>	</entry>

	</feed>