page397.html

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

HTML
50
字号
<HTML><HEAD><TITLE>Array 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="tex2html5757" HREF="page398.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html5755" HREF="page396.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html5749" HREF="page396.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html5759" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H2><A NAME="SECTION0012310000000000000000">Array Implementation</A></H2><P>A regular set may contain either zero or one instance of a particular item.As shown in the preceding sectionif the number of possible items is not excessive,we may use an array of <tt>bool</tt> variables to keep track of thenumber of instances of a particular item in a regular set.The natural extension of this idea for a multiset is to keep a separatecount of the number of instances of each item in the multiset.<P>Program&nbsp;<A HREF="page397.html#progmultisetAsArraya"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> introduces the <tt>MultisetAsArray</tt> class.The <tt>MultisetAsArray</tt> class extendsthe abstract <tt>Multiset</tt> classdefined in Program&nbsp;<A HREF="page396.html#progmultiseta"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.The multiset is implemented usingan array of  <IMG WIDTH=44 HEIGHT=11 ALIGN=BOTTOM ALT="tex2html_wrap_inline66691" SRC="img1559.gif"  > counters.Each counter is an <tt>int</tt> in this case.<P><P><A NAME="28238">&#160;</A><A NAME="progmultisetAsArraya">&#160;</A> <IMG WIDTH=575 HEIGHT=180 ALIGN=BOTTOM ALT="program27948" SRC="img1585.gif"  ><BR><STRONG>Program:</STRONG> <tt>MultisetAsArray</tt> class <tt>__init__</tt> method.<BR><P><P>In addition to <tt>self</tt>,the <tt>__init__</tt> method takes a single argument, <IMG WIDTH=145 HEIGHT=11 ALIGN=BOTTOM ALT="tex2html_wrap_inline66681" SRC="img1556.gif"  >,and initializes an array of length <I>N</I> counters all to zero.The running time of the <tt>__init__</tt> method is <I>O</I>(<I>N</I>).<P><BR> <HR><UL> <LI> <A NAME="tex2html5760" HREF="page398.html#SECTION0012311000000000000000">Basic Operations</A><LI> <A NAME="tex2html5761" HREF="page399.html#SECTION0012312000000000000000">Union, Intersection, and Difference</A></UL><HR><A NAME="tex2html5757" HREF="page398.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html5755" HREF="page396.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html5749" HREF="page396.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html5759" 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 + -
显示快捷键?