graphmatrixundirected.html

来自「学习JAVA的很好的JAVA包和文档包」· HTML 代码 · 共 412 行 · 第 1/2 页

HTML
412
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd"><!--NewPage--><HTML><HEAD><!-- Generated by javadoc on Fri Aug 23 13:18:17 EDT 2002 --><TITLE>: Class  GraphMatrixUndirected</TITLE><LINK REL ="stylesheet" TYPE="text/css" HREF="../stylesheet.css" TITLE="Style"></HEAD><BODY BGCOLOR="white"><!-- ========== START OF NAVBAR ========== --><A NAME="navbar_top"><!-- --></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0"><TR><TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"><A NAME="navbar_top_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">  <TR ALIGN="center" VALIGN="top">  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>  </TR></TABLE></TD><TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM><a href=../copyright.html target=_top>&copy; 1998-2002 McGraw-Hill</a></EM></TD></TR><TR><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">&nbsp;<A HREF="../structure/GraphMatrixDirected.html"><B>PREV CLASS</B></A>&nbsp;&nbsp;<A HREF="../structure/GraphMatrixVertex.html"><B>NEXT CLASS</B></A></FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">  <A HREF="../index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;&nbsp;<A HREF="GraphMatrixUndirected.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">  SUMMARY: &nbsp;INNER&nbsp;|&nbsp;<A HREF="#fields_inherited_from_class_structure.GraphMatrix">FIELD</A>&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">DETAIL: &nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD></TR></TABLE><!-- =========== END OF NAVBAR =========== --><HR><!-- ======== START OF CLASS DATA ======== --><H2><FONT SIZE="-1">structure</FONT><BR>Class  GraphMatrixUndirected</H2><PRE><A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html">java.lang.Object</A>  |  +--<A HREF="../structure/AbstractStructure.html">structure.AbstractStructure</A>        |        +--<A HREF="../structure/GraphMatrix.html">structure.GraphMatrix</A>              |              +--<B>structure.GraphMatrixUndirected</B></PRE><DL><DT><B>All Implemented Interfaces:</B> <DD><A HREF="../structure/Graph.html">Graph</A>, <A HREF="../structure/Structure.html">Structure</A></DD></DL><HR><DL><DT>public class <B>GraphMatrixUndirected</B><DT>extends <A HREF="../structure/GraphMatrix.html">GraphMatrix</A></DL><P>A GraphMatrixUndirected is a matrix-based graph representation that  consists of a collection of vertices and undirected edges.  Portions of  the graph may be marked visited to support iterative algorithms.   Iteration is provided over vertices, edges, and vertices adjacent to a particular vertex. GraphMatrix differs from GraphList in that the user must commit to  an upper bound on number of vertices in graph. <P> Example Usage:  <P>  To create a graph representation of the movie theaters nearest the Williams College Department of Computer Science's unix laboratory,  and to print these theaters out in order of increasing distance, we could use the following: <P> <pre>  public static void main(String[] argv){	Graph theaters = new <A HREF="../structure/GraphMatrixUndirected.html#GraphMatrixUndirected(int)"><CODE>GraphMatrixUndirected(9)</CODE></A>;	FibHeap heap = new FibHeap();		//instantiate array of locations 	String[] locations = new String[]{"TCL 312", "Images Cinema", 					  "Movie Plex 3", "Cinema 1,2,&3", 					  "Cinema 7", "Berkshire Mall Cinemas"					  ,"Hathaway's Drive Inn Theatre",					  "Hollywood Drive-In Theatre"};	//instantiate array of distances between <code>location[0]</code> 	//and movie theaters	double[] distances =  new double[]{-1, 0.0, 12.6, 12.9, 12.9, 					   14.7, 16.5, 18.0};		//build graph	for(int i=0; i < locations.length; i++) theaters.add(locations[i]);	for(int i=1; i < distances.length; i++){	  theaters.<A HREF="../structure/GraphMatrixUndirected.html#addEdge(java.lang.Object, java.lang.Object, java.lang.Object)"><CODE>addEdge(locations[0],locations[i],new Double(distances[i]))</CODE></A>;	}		//place neighbors of lab in into priority queue	for(Iterator i=theaters.<A HREF="../structure/GraphMatrix.html#neighbors(java.lang.Object)"><CODE>neighbors(locations[0])</CODE></A>; i.hasNext();){	    Object theater = i.next();	    Object distance = theaters.<A HREF="../structure/GraphMatrix.html#getEdge(java.lang.Object, java.lang.Object)"><CODE>getEdge(locations[0], theater).label()</CODE></A>;	    heap.add(new ComparableAssociation((Comparable)distance,theater));	}		//print out theaters in order of distance	while(!heap.isEmpty()){	    ComparableAssociation show = (ComparableAssociation)heap.remove();	    System.out.println(show.getValue()+" is "+show.getKey()+" miles away.");	}  } </pre><P><DL><DT><B>See Also: </B><DD><A HREF="../structure/GraphMatrix.html"><CODE>GraphMatrix</CODE></A>, <A HREF="../structure/GraphMatrixDirected.html"><CODE>GraphMatrixDirected</CODE></A>, <A HREF="../structure/GraphListUndirected.html"><CODE>GraphListUndirected</CODE></A></DL><HR><P><!-- ======== INNER CLASS SUMMARY ======== --><!-- =========== FIELD SUMMARY =========== --><A NAME="fields_inherited_from_class_structure.GraphMatrix"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor"><TD><B>Fields inherited from class structure.<A HREF="../structure/GraphMatrix.html">GraphMatrix</A></B></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><A HREF="../structure/GraphMatrix.html#data">data</A>, <A HREF="../structure/GraphMatrix.html#dict">dict</A>, <A HREF="../structure/GraphMatrix.html#directed">directed</A>, <A HREF="../structure/GraphMatrix.html#freeList">freeList</A>, <A HREF="../structure/GraphMatrix.html#size">size</A></CODE></TD></TR></TABLE>&nbsp;<!-- ======== CONSTRUCTOR SUMMARY ======== --><A NAME="constructor_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Constructor Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="../structure/GraphMatrixUndirected.html#GraphMatrixUndirected(int)">GraphMatrixUndirected</A></B>(int&nbsp;size)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Construct an undirected, adjacency-matrix based graph.</TD></TR></TABLE>&nbsp;<!-- ========== METHOD SUMMARY =========== --><A NAME="method_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Method Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;void</CODE></FONT></TD><TD><CODE><B><A HREF="../structure/GraphMatrixUndirected.html#addEdge(java.lang.Object, java.lang.Object, java.lang.Object)">addEdge</A></B>(<A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html">Object</A>&nbsp;vLabel1,        <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html">Object</A>&nbsp;vLabel2,        <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html">Object</A>&nbsp;label)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Add an edge between two vertices within the graph.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;int</CODE></FONT></TD><TD><CODE><B><A HREF="../structure/GraphMatrixUndirected.html#edgeCount()">edgeCount</A></B>()</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Determine the number of edges in graph.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;<A HREF="http://java.sun.com/j2se/1.3/docs/api/java/util/Iterator.html">Iterator</A></CODE></FONT></TD><TD><CODE><B><A HREF="../structure/GraphMatrixUndirected.html#edges()">edges</A></B>()</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Construct an traversal over all edges.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;<A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html">Object</A></CODE></FONT></TD><TD><CODE><B><A HREF="../structure/GraphMatrixUndirected.html#removeEdge(java.lang.Object, java.lang.Object)">removeEdge</A></B>(<A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html">Object</A>&nbsp;vLabel1,           <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html">Object</A>&nbsp;vLabel2)</CODE>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?