The implementation code of the Python selection sorting algorithm _python

Source: Internet
Author: User

1. Algorithm:
For a group of keywords {k1,k2,..., kn}, first select the minimum value from the K1,k2,..., kn, and if it is a KZ, swap the KZ with the K1;
Then from K2,k3, ..., kn, select the minimum value KZ, and then swap the KZ with the K2.
So choose and switch n-2, n-1, select the minimum value from the Kn-1 and kn the KZ will swap the KZ and the Kn-1, the last remaining is the maximum value in the sequence, a sequence from small to large is formed.

2.python Select Sorting code:

Copy Code code as follows:

def selection_sort (List2):
For I in range (0, Len (list2)):
Min = i
For j in range (i + 1, len (LIST2)):
If LIST2[J] < List2[min]:
Min = J
List2[i], list2[min] = List2[min], list2[i] # Swap

The results are: [2, 3, 4, 21, 33, 44, 45, 67]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.