⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 page543.html

📁 Data Structures And Algorithms With Object-Oriented Design Patterns In Python (2003) source code and
💻 HTML
字号:
<HTML><HEAD><TITLE>Using Adjacency Matrices</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="tex2html7408" HREF="page544.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html7406" HREF="page542.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html7400" HREF="page542.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html7410" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H3><A NAME="SECTION0016271000000000000000">Using Adjacency Matrices</A></H3><P>The <tt>GraphAsMatrix</tt> class is introduced in Program&nbsp;<A HREF="page543.html#proggraphAsMatrixa"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.The <tt>GraphAsMatrix</tt> class extendsthe abstract <tt>Graph</tt> classintroduced in Programs&nbsp;<A HREF="page537.html#proggrapha"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>, <A HREF="page538.html#proggraphb"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> and&nbsp;<A HREF="page539.html#proggraphc"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.<P><P><A NAME="50008">&#160;</A><A NAME="proggraphAsMatrixa">&#160;</A> <IMG WIDTH=575 HEIGHT=142 ALIGN=BOTTOM ALT="program49779" SRC="img2271.gif"  ><BR><STRONG>Program:</STRONG> <tt>GraphAsMatrix</tt> class <tt>__init__</tt> method.<BR><P><P>Each instance of the <tt>GraphAsMatrix</tt> classrepresents an undirected graph, say  <IMG WIDTH=73 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline70549" SRC="img2166.gif"  >.The set of vertices,  <IMG WIDTH=11 HEIGHT=12 ALIGN=BOTTOM ALT="tex2html_wrap_inline70551" SRC="img2167.gif"  >, is represented usingthe <tt>_vertex</tt> array inherited from the abstract <tt>Graph</tt> base class.Each vertex is represented by a separate <tt>Graph.Vertex</tt> instance.<P>Similarly,The set of edges,  <IMG WIDTH=9 HEIGHT=13 ALIGN=BOTTOM ALT="tex2html_wrap_inline70557" SRC="img2168.gif"  >, is represented usingthe <tt>_matrix</tt> instance attributewhich is a two-dimensional array of <tt>Edge</tt>s.Each edge is represented by a separate <tt>Graph.Edge</tt> instance.<P>In addition to <tt>self</tt>,the <tt>GraphAsMatrix</tt> <tt>__init__</tt> method takes a single argumentof type <tt>int</tt> that specifiesthe maximum number of vertices that the graph may contain.This quantity specifies the length of thearray of vertices and the dimensions of the adjacency matrix.The implementation of the <tt>GraphAsMatrix</tt> class is leftas programming project for the reader (Project&nbsp;<A HREF="page584.html#projectgraphsmatrix"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>).<P><HR><A NAME="tex2html7408" HREF="page544.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html7406" HREF="page542.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html7400" HREF="page542.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html7410" 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 &#169; 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 + -