page129.html
来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 66 行
HTML
66 行
<HTML><HEAD><TITLE>Projects</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="tex2html2689" HREF="page130.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html2687" HREF="page111.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html2683" HREF="page128.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html2691" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H1><A NAME="SECTION005400000000000000000">Projects</A></H1><P><OL><LI> <A NAME="projectadtscompare"> </A> Design and implement suitable wrapper classes that extend the <tt>Object</tt> base class for the Python types <tt>bool</tt>, <tt>int</tt>, <tt>str</tt>, and <tt>tuple</tt>.<LI> Using <em>visitors</em>, devise an implementation for the <tt>__contains__</tt> method and the <tt>find</tt> method of the <tt>SearchableContainer</tt> class declared in Program <A HREF="page126.html#progsearchableContainera"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.<LI> Using an <em>iterator</em>, devise an implementation for the <tt>__contains__</tt> method and the <tt>find</tt> method of the <tt>SearchableContainer</tt> class declared in Program <A HREF="page126.html#progsearchableContainera"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.<LI> Devise a scheme using visitors whereby all of the objects contained in one searchable container can be removed from it and transfered to another container.<LI> <A NAME="projectadtsbag"> </A> A <em>bag</em><A NAME=4915> </A> is a simple container that can hold a collection of objects. Design and implement a concrete class called <tt>Bag</tt> that extends the <tt>SearchableContainer</tt> class defined in Program <A HREF="page126.html#progsearchableContainera"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>. Use the <tt>Array</tt> class given in Chapter <A HREF="page81.html#chapfds"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> to keep track of the contents of the bag.<LI> Repeat Project <A HREF="page129.html#projectadtsbag"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>, this time using the <tt>LinkedList</tt> class given in Chapter <A HREF="page81.html#chapfds"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.<LI> In Java it is common to use an <em>enumeration</em><A NAME=4925> </A> as the means to iterate through the objects in a container. In Python we can define an enumeration like this:<PRE>class Enumeration(Object): def hasMoreElements(): pass hasMoreElements = abstractmethod(hasMoreElements) def nextElement(): pass nextElement = abstractmethod(nextElement)</PRE> Given an enumeration <tt>e</tt> from some container <tt>c</tt>, the contents of <tt>c</tt> can be printed like this:<PRE>while (e.hasMoreElements()): print e.nextElement()</PRE> Devise a wrapper class to encapsulate a Python iterator and provide the functionality of a Java enumeration.</OL><P><HR><A NAME="tex2html2689" HREF="page130.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html2687" HREF="page111.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html2683" HREF="page128.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html2691" 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 © 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 + -
显示快捷键?