Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Selection sort
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Example == Here is an example of this sort algorithm sorting five elements: {| class="wikitable" ! Sorted sublist ! Unsorted sublist ! Least element in unsorted list |- | () | style="text-align:right;" | (12, 25, 64, 11, 22) | 11 |- | (11) | style="text-align:right;" | (25, 64, 12, 22) | 12 |- | (11, 12) | style="text-align:right;" | (64, 25, 22) | 22 |- | (11, 12, 22) | style="text-align:right;" | (25, 64) | 25 |- | (11, 12, 22, 25) | style="text-align:right;" | (64) | 64 |- | (11, 12, 22, 25, 64) | style="text-align:right;" | () | |} [[Image:Selection-Sort-Animation.gif|right|thumb|Selection sort animation. Red is current min. Yellow is sorted list. Blue is current item.]] (Nothing appears changed on these last two lines because the last two numbers were already in order.) Selection sort can also be used on list structures that make add and remove efficient, such as a [[linked list]]. In this case it is more common to ''remove'' the minimum element from the remainder of the list, and then ''insert'' it at the end of the values sorted so far. For example: <pre style="overflow:auto; width:auto;"> arr[] = 64 25 12 22 11 // Find the minimum element in arr[0...4] // and place it at beginning 11 25 12 22 64 // Find the minimum element in arr[1...4] // and place it at beginning of arr[1...4] 11 12 25 22 64 // Find the minimum element in arr[2...4] // and place it at beginning of arr[2...4] 11 12 22 25 64 // Find the minimum element in arr[3...4] // and place it at beginning of arr[3...4] 11 12 22 25 64 </pre>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)