Algorithm: Quick Sort

Source: Internet
Author: User

1 #Coding:utf-82 3 ImportRandom4 Import Time5 6t =time.time ()7 8 #Fast Sorting segmentation algorithm, reference self-programming Zhu Ji Nanxiong9 #[L, R] is closed intervalTen defpartion (A, L, R): One     #tmp = a[0] A     ifL >=r: -         return -m =L the     #for I in range (1, Len (a)): -      forIinchRange (L + 1, R + 1): -         ifA[i] <A[l]: -M + = 1 +A[M], a[i] =A[i], A[m] -  +A[l], a[m] =A[m], A[l] APartion (A, L, m-1) atPartion (A, M + 1, R) -     returnm -  - #def qsort (): - if __name__=="__main__": -N = 100000 inA = [Random.randint (1,100000) forIinchrange (N)] -Partion (A, 0, N-1) to     Printa +b =a[:]; A.sort () -     Printb = =a the     PrintTime.time ()-T

Fast-sorting Python implementations

References: Programming Zhu Ji Nanxiong

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