Python Select sort

Source: Internet
Author: User

The idea of choosing a sorting algorithm first first selects the smallest number from the entire sequence, then puts it first, then selects the smallest number from the second to the last, puts the number in the second position, and then, from the third to the last, selects the smallest of the numbers into the third position, so that it goes down until the last one. So that we can form an orderly sequence.

Select a value to compare, all compared, the maximum value is placed on the last side. And then continue to compare

#-*-encoding:utf-8-*-li=[1,2222,55555,12,31,32,13,23] forIinchRange (len (LI)): K=i#I equals the first position     forJinchRange (I+1,len (LI)):#J equals a second position        ifLI[K] > Li[j]:#If the first one is bigger than the second one ,LI[K],LI[J]=LI[J],LI[K]#Position SwapI= (#otherwise the position remains unchanged, followed by a continuation match.     #at the end of each cycle, the maximum value is reachedPrint(LI)

Python Select sort

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.