Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Selection sort
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
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>
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Selection sort
(section)
Add topic