"Red is current min. Yellow is sorted list. Blue is current item." ~Wikipedia |
So blue iterates through the list, comparing values as it goes along. The current minimum value is stored in red. By the time the end of the list is reached (with blue), the value that is red at that time, will be the smallest value in the "active part" of the list.
It is moved to the end of the "passive section", marked in yellow. Once it is yellow, it doesn't need to search it again, as it's already where it should be.
Please note: The algorithm doesn't really use colours. They are just for visualisation.
"Selection sort" because it selects the smallest value and works with that.
wikipedia link
Gypsy folk dance. Lol.
ReplyDelete