Python Quick Find algorithm application example _python

Source: Internet
Author: User

This article illustrates the application of Python fast lookup algorithm, and share it for everyone's reference.

The implementation methods are as follows:

Import Random
def partition (list_object,start,end):
  random_choice = Start
  #random. Choice (Start, end+1)
  #把这里的start改成random () efficiency will be higher
  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
  J

def 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

Program test environment for Python2.7.6

The output results are as follows:

[Si, 6, mb
, M, [6, Panax Notoginseng
, Si, the [6, Panax Notoginseng
, Si, the [6, Panax Notoginseng, si,
the [6, Panax Notoginseng, si,
the [6, 28, 37, 54, 65, 69, 90, 92]

I hope this article will help you with your 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.