page91.html

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

HTML
42
字号
<HTML><HEAD><TITLE>An Implementation</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="tex2html2260" HREF="page92.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html2258" HREF="page89.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html2252" HREF="page90.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html2262" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H2><A NAME="SECTION004220000000000000000">An Implementation</A></H2><A NAME="secfdsarray2d">&#160;</A><P>In this section we illustrate the implementation of amulti-dimensional array using a one-dimensional array.We do this by defining a class called <tt>MultiDimensionalArray</tt>that is very similar to the <tt>Array</tt> classdefined in Section&nbsp;<A HREF="page83.html#secfdsarrayimp"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.<P>Altogether three instance attributes are usedto implement the <tt>MultiDimensionalArray</tt> class.The first, <tt>_dimensions</tt> is an array of length <I>n</I>,where <I>n</I> is number of dimensionsand  <IMG WIDTH=89 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline60501" SRC="img607.gif"  >is the size of the  <IMG WIDTH=17 HEIGHT=14 ALIGN=BOTTOM ALT="tex2html_wrap_inline57847" SRC="img77.gif"  > dimension ( <IMG WIDTH=11 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline60505" SRC="img608.gif"  >).<P>The second instance attribute, <tt>_factors</tt>,is also an array of length <I>n</I>.The  <IMG WIDTH=20 HEIGHT=28 ALIGN=MIDDLE ALT="tex2html_wrap_inline60509" SRC="img609.gif"  > element of the <tt>factors</tt> arraycorresponds to the factor  <IMG WIDTH=12 HEIGHT=25 ALIGN=MIDDLE ALT="tex2html_wrap_inline60489" SRC="img604.gif"  > given by Equation&nbsp;<A HREF="page90.html#eqnfdsfactors"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.<P>The third instance attribute, <tt>_data</tt>,is a one-dimensional array used to hold the elementsof the multi-dimensional array in row-major order.<P><HR><A NAME="tex2html2260" HREF="page92.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html2258" HREF="page89.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html2252" HREF="page90.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html2262" 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 + -
显示快捷键?