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

📄 page390.html

📁 Data Structures And Algorithms With Object-Oriented Design Patterns In Python (2003) source code and
💻 HTML
字号:
<HTML><HEAD><TITLE>Basic Operations</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="tex2html5682" HREF="page391.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html5680" HREF="page389.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html5674" HREF="page389.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html5684" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H3><A NAME="SECTION0012201000000000000000">Basic Operations</A></H3><P>Program&nbsp;<A HREF="page390.html#progsetAsArrayb"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> shows the <tt>insert</tt>, <tt>__contains__</tt>,and <tt>withdraw</tt> methods of the <tt>SetAsArray</tt> class.The <tt>insert</tt> method is used to put an item into the set.The method takes an <tt>int</tt> argument that specifies the item to be inserted.Then the corresponding element of <tt>_array</tt> is set to <tt>True</tt>to indicate that the item has been added to the set.The running time of the <tt>insert</tt> operation is <I>O</I>(1).<P><P><A NAME="28208">&#160;</A><A NAME="progsetAsArrayb">&#160;</A> <IMG WIDTH=575 HEIGHT=237 ALIGN=BOTTOM ALT="program27723" SRC="img1560.gif"  ><BR><STRONG>Program:</STRONG> <tt>SetAsArray</tt> class <tt>insert</tt>, 	<tt>__contains__</tt> and <tt>withdraw</tt> methods.<BR><P><P>The <tt>__contains__</tt> method is used to test whether a given itemis an element of the set.The semantics are somewhat subtle.Since a set does not actually keep track ofthe specific object instances that are inserted,the membership test is based on the <em>value</em> of the argument.The method simply returns the value of the appropriateelement of the <tt>_array</tt>.The running time of the <tt>__contains__</tt> operation is <I>O</I>(1).<P>The <tt>withdraw</tt> method is used to take an item out of a set.The withdrawal operation is the opposite of insertion.Instead of setting the appropriate array element to <tt>True</tt>,it is set to <tt>False</tt>.The running time of the <tt>withdraw</tt>is identical to that of <tt>insert</tt>, viz., is <I>O</I>(1).<P><HR><A NAME="tex2html5682" HREF="page391.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html5680" HREF="page389.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html5674" HREF="page389.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html5684" 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 + -