page498.html

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

HTML
50
字号
<HTML><HEAD><TITLE>Straight Selection Sorting</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="tex2html6899" HREF="page499.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html6897" HREF="page497.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html6891" HREF="page497.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html6901" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H2><A NAME="SECTION0015510000000000000000">Straight Selection Sorting</A></H2><P>The simplest of the selection sorts is called<em>straight selection</em><A NAME=37881>&#160;</A>.Figure&nbsp;<A HREF="page498.html#figsort4"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> illustrates how straight selection works.In the version shown,the sorted list is constructed from the right(i.e., from the largest to the smallest element values).<P><P><A NAME="39041">&#160;</A><A NAME="figsort4">&#160;</A> <IMG WIDTH=575 HEIGHT=546 ALIGN=BOTTOM ALT="figure37883" SRC="img2068.gif"  ><BR><STRONG>Figure:</STRONG> Straight selection sorting.<BR><P><P>At each step of the algorithm,a linear search of the unsorted elements is madein order to determine the position of the largest remaining element.That element is then moved into the correct position of the arrayby swapping it with the element which currently occupies that position.<P>For example, in the first step shown in Figure&nbsp;<A HREF="page498.html#figsort4"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>,a linear search of the entire array reveals that 9 is the largest element.Since 9 is the largest element, it belongs in the last array position.To move it there, we swap it with the 4 that initially occupies that position.The second step of the algorithm identifies 6 as the largest remainingelement an moves it next to the 9.Each subsequent step of the algorithm movesone element into its final position.Therefore, the algorithm is done after <I>n</I>-1 such steps.<P><BR> <HR><UL> <LI> <A NAME="tex2html6902" HREF="page499.html#SECTION0015511000000000000000">Implementation</A></UL><HR><A NAME="tex2html6899" HREF="page499.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html6897" HREF="page497.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html6891" HREF="page497.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html6901" 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 + -
显示快捷键?