Python Quick Find Algorithm application example

Source: Internet
Author: User
In this paper, we describe the application of Python Quick Find algorithm and share it for your reference.

The implementation method is as follows:

Import randomdef partition (List_object,start,end):  random_choice = Start  #random. Choice (Range (start,end+1) )  #把这里的start改成random () is more efficient  x = List_object[random_choice]  i = start  j = End While  True:    While List_object[i] < x and I < end:      i + = 1 while    list_object[j] > x:      J-= 1    if I >= j:
  break    List_object[i],list_object[j] = list_object[j],list_object[i]  print list_object  #list_ Object[random_choice] = list_object[j]  #list_object [j] = Random_choice  return jdef quick_sort (List_object, Start,end):  If start < end:    temp = partition (list_object,start,end)    Quick_sort (List_object,start, temp-1)    Quick_sort (list_object,temp + 1, end)    a_list = [69,65,90,37,92,6,28,54]quick_sort (a_list,0,7) Print A_list

The program test environment is Python2.7.6

The output results are as follows:

[54, 65, 28, 37, 6, 69, 92, 90] [6, 37, 28, 54, 65, 69, 92, 90] [6, 37, 28, 54, 65, 69, 92, 90] [6, 28, 37, 54, 65, 69, 92, 90] [6, 28, 37, 54, 65, 69, 90, 92] [6, 28, 37, 54, 65, 69, 90, 92]

Hopefully this article will help you with Python programming.

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