page544.html

来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 51 行

HTML
51
字号
<HTML><HEAD><TITLE>Using Adjacency Lists</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="tex2html7417" HREF="page545.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html7415" HREF="page542.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html7411" HREF="page543.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html7419" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H3><A NAME="SECTION0016272000000000000000">Using Adjacency Lists</A></H3><P>Program&nbsp;<A HREF="page544.html#proggraphAsListsa"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> introduces the <tt>GraphAsLists</tt> class.The <tt>GraphAsLists</tt> extends the 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>.The <tt>GraphAsLists</tt> class represents the edgesof a graph using adjacency lists.<P><P><A NAME="50011">&#160;</A><A NAME="proggraphAsListsa">&#160;</A> <IMG WIDTH=575 HEIGHT=199 ALIGN=BOTTOM ALT="program49811" SRC="img2272.gif"  ><BR><STRONG>Program:</STRONG> <tt>GraphAsLists</tt> class <tt>__init__</tt> method.<BR><P><P>Each instance of the <tt>GraphAsLists</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.The set of edges,  <IMG WIDTH=9 HEIGHT=13 ALIGN=BOTTOM ALT="tex2html_wrap_inline70557" SRC="img2168.gif"  >, is represented usingthe <tt>_adjacencyList</tt> instance attribute,which is an array of linked lists.The  <IMG WIDTH=17 HEIGHT=14 ALIGN=BOTTOM ALT="tex2html_wrap_inline57847" SRC="img77.gif"  > linked list, <tt>_adjacencyList[i]</tt>,represents the set  <IMG WIDTH=37 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline71077" SRC="img2273.gif"  > which isthe set of edges emanating from vertex  <IMG WIDTH=12 HEIGHT=14 ALIGN=MIDDLE ALT="tex2html_wrap_inline70715" SRC="img2201.gif"  >.The implementation uses the <tt>LinkedList</tt> classgiven in Section&nbsp;<A HREF="page97.html#secfdslinklist"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.<P>In addition to <tt>self</tt>,the <tt>GraphAsLists</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 lengths of thearray of vertices and the array of adjacency lists.The implementation of the <tt>GraphAsLists</tt> class is leftas programming project for the reader (Project&nbsp;<A HREF="page584.html#projectgraphslists"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>).<P><HR><A NAME="tex2html7417" HREF="page545.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html7415" HREF="page542.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html7411" HREF="page543.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html7419" 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 + =
减小字号Ctrl + -
显示快捷键?