📄 page537.html
字号:
<HTML><HEAD><TITLE>Abstract Graphs</TITLE></HEAD><BODY bgcolor="#FFFFFF"> <a href="../index.html" target="_top"><img src="../icons/usins.gif" alt="Logo" align=right></a><b>Data Structures and Algorithms with Object-Oriented Design Patterns in Python</b><br><A NAME="tex2html7342" HREF="page538.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html7340" HREF="page532.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html7334" HREF="page536.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html7344" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H2><A NAME="SECTION0016240000000000000000">Abstract Graphs</A></H2><P>Program <A HREF="page537.html#proggrapha"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> introduces the <tt>Graph</tt> class.The abstract <tt>Graph</tt> classextends the abstract <tt>Container</tt> classintroduced in Program <A HREF="page119.html#progcontainera"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.<P><P><A NAME="49966"> </A><A NAME="proggrapha"> </A> <IMG WIDTH=575 HEIGHT=600 ALIGN=BOTTOM ALT="program49556" SRC="img2267.gif" ><BR><STRONG>Program:</STRONG> Abstract <tt>Graph</tt>, <tt>Graph.Vertex</tt> and <tt>Graph.Edge</tt> <tt>__init__</tt> methods.<BR><P><P>The abstract <tt>Graph</tt> class serves as the base class from whichthe various concrete graph implementationsdiscussed in Section <A HREF="page542.html#secgraphsimplement"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> are derived.The abstract <tt>Graph</tt> class also provides implementationsfor the graph traversals described in Section <A HREF="page548.html#secgraphtraversals"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>and for the algorithms that test for cycles and connectednessdescribed in Section <A HREF="page558.html#secgraphconnected"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.<P>As shown in Program <A HREF="page537.html#proggrapha"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>,the abstract <tt>Graph</tt> class definestwo nested classes,<tt>Vertex</tt> and <tt>Edge</tt>.<P>The concrete <tt>Graph.Vertex</tt> class extendsthe abstract <tt>Vertex</tt> classdefined in Program <A HREF="page533.html#progvertexa"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.It comprises three instance attributes--<tt>_graph</tt>, <tt>_number</tt> and <tt>_weight</tt>.The <tt>_graph</tt> instance attributerefers to the graph instance that contains this vertex.Each vertex in a graph with <I>n</I> vertices is assigned a unique numberin the interval [0,<I>n</I>-1].The <tt>_number</tt> instance attribute records this number.The <tt>_weight</tt> instance attribute is used to recordthe weight on a weighted vertex.<P>The concrete <tt>Graph.Edge</tt> class extendsthe abstract <tt>Edge</tt> classdefined in Program <A HREF="page535.html#progedgea"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.It comprises four instance attributes--<tt>_graph</tt>, <tt>_v0</tt>, <tt>_v1</tt>, and <tt>_weight</tt>.The <tt>_graph</tt> instance attribute refers tothe graph instance that contains this edge.The <tt>_v0</tt> and <tt>_v1</tt> attributes record the verticesthat are the end-points of the edge.The <tt>_weight</tt> instance attribute is used to recordthe weight on a weighted edge.<P><BR> <HR><UL> <LI> <A NAME="tex2html7345" HREF="page538.html#SECTION0016241000000000000000">Properties</A></UL><HR><A NAME="tex2html7342" HREF="page538.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html7340" HREF="page532.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html7334" HREF="page536.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html7344" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <P><ADDRESS><img src="../icons/bruno.gif" alt="Bruno" align=right><a href="../copyright.html">Copyright © 2003</a> by <a href="../signature.html">Bruno R. Preiss, P.Eng.</a> All rights reserved.</ADDRESS></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -