Choose Sort Python

Source: Internet
Author: User

Select Sort is a simpler sort, and its main idea is to find the smallest number each time the loop is sorted, put it first in the unsorted sub-array, and then proceed to the next loop.

The next time the loop, there is a number of sequential, less a comparison. This is accomplished with Python:

Def Choose_sort (a):        N = Len (a) for    I in range (0, N):         min_index = i               #最小数的起始位置        for J in range (I+1, n): 
    #每次从未排序的子数组开始循环             if A[min_index] > a[j]:                  min_index = j       #遇到比自己小的就把它的位置保存在min_index中        t = a[i]                             A[i] = A[min_index]         #把最小值保存在a [i], I is the starting position of the Subarray, the loop starts from i+1        a[min_index] = t            #把原来a [i] The value inside is saved to the location of the original minimum value, complete the Exchange    return a

Choose Sort Python

Related Article

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: 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.