Select the sort Python implementation

Source: Internet
Author: User

Import Randomimport datetime# Select Sort def getmaxindex (index, LS), int: "" ": Type ls list:type index:int:return:" "" # Select Rows The order is initially considered the largest maxindex of the current number = Indexlength = Len (ls) for I in range (index, length): if ls[i] > ls[maxindex]:maxindex = Iretu RN Maxindex def selectsort (data), List: "" "Select Sort: Type Data:list:return:" "" "" Length = Len (data) print ("Pre-sort-->%s"% dat a) start = Datetime.datetime.now (). Strftime ("%y-%m-%d%h:%m:%s") print (start) for I in range (length): Themax = Getmaxindex (I, data) if I! = Themax:temp = data[themax]# Move Large data forward one data[themax] = data[i]data[i] = Tempend = Datetime.datetime.now (). s Trftime ("%y-%m-%d%h:%m:%s") print (end) return data if __name__ = = "__main__":d Atas = List () for J in Range (10000): integer =  Random.choice (range (1)) datas.append (integer) Sort_result = Selectsort (datas) print ("-->%s after sorting"% Sort_result) Sort 10,000 elements to probably need a 5s

Select the sort Python implementation

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.