page481.html

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

HTML
54
字号
<HTML><HEAD><TITLE>Abstract Sorters</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="tex2html6709" HREF="page482.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html6707" HREF="page480.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html6701" HREF="page480.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html6711" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H3><A NAME="SECTION0015201000000000000000">Abstract Sorters</A></H3><P>Program&nbsp;<A HREF="page481.html#progsortera"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> defines the <tt>Sorter</tt> class.The abstract <tt>Sorter</tt> classextends the abstract <tt>Object</tt> classintroduced in Program&nbsp;<A HREF="page116.html#progobjecta"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.<P><P><A NAME="34442">&#160;</A><A NAME="progsortera">&#160;</A> <IMG WIDTH=575 HEIGHT=451 ALIGN=BOTTOM ALT="program34379" SRC="img1990.gif"  ><BR><STRONG>Program:</STRONG> Abstract <tt>Sorter</tt> class.<BR><P><P>The <tt>Sorter</tt> comprises the two instance attributes,<tt>_array</tt> and <tt>_n</tt>,the concrete methods <tt>sort</tt> and <tt>swap</tt>,and the abstract method <tt>_sort</tt>.Since the <tt>_sort</tt> method is an abstract method,an implementation must be given in a derived class.<P>The <tt>sort</tt> method does not sort the data itself.It is the <tt>_sort</tt> method,which is provided by a derived class,that does the actual sorting.The <tt>sort</tt> method merely sets-up thingsby initializing the instance attributes of <tt>Sorter</tt> as follows:The <tt>_array</tt> instance attributerefers to the array of objects to be sortedand the length of that array is assigned to <tt>_n</tt>.<P>The <tt>swap</tt> method is used to implement most of the sortingalgorithms presented in this chapter.In addition to <tt>self</tt>,the swap method takes two integers arguments.It exchanges the contents of the arrayat the positions specified by those arguments.The exchange is done as a sequence of three assignments.Therefore, the <tt>swap</tt> method runs in constant time.<P><HR><A NAME="tex2html6709" HREF="page482.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html6707" HREF="page480.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html6701" HREF="page480.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html6711" 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 + -
显示快捷键?