📄 page497.html
字号:
<HTML><HEAD><TITLE>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="tex2html6885" HREF="page498.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html6883" HREF="page478.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html6877" HREF="page496.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html6887" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H1><A NAME="SECTION0015500000000000000000">Selection Sorting</A></H1><P>The third class of sorting algorithm that we consider comprises algorithmsthat sort <em>by selection</em><A NAME=37872> </A><A NAME=37873> </A>.Such algorithms construct the sorted sequence one element at a timeby adding elements to the sorted sequence <em>in order</em>.At each step, the next element to be added to the sorted sequenceis selected from the remaining elements.<P>Because the elements are added to the sorted sequence in order,they are always added at one end.This is what makes selection sorting different from insertion sorting.In insertion sorting elements are added to the sorted sequencein an arbitrary order.Therefore, the position in the sorted sequence at which each subsequentelement is inserted is arbitrary.<P>Both selection sorts described in this section sort the arrays<em>in place</em><A NAME=37876> </A><A NAME=37877> </A>.Consequently, the sorts are implemented by exchanging array elements.Nevertheless, selection differs from exchange sortingbecause at each step we <em>select</em> the next element of the sorted sequencefrom the remaining elementsand then we move it into its final position in the arrayby exchanging it with whatever happens to be occupying that position.<P><BR> <HR><UL> <LI> <A NAME="tex2html6888" HREF="page498.html#SECTION0015510000000000000000">Straight Selection Sorting</A><LI> <A NAME="tex2html6889" HREF="page500.html#SECTION0015520000000000000000">Sorting with a Heap</A><LI> <A NAME="tex2html6890" HREF="page502.html#SECTION0015530000000000000000">Building the Heap</A></UL><HR><A NAME="tex2html6885" HREF="page498.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html6883" HREF="page478.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html6877" HREF="page496.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html6887" 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -