Python insert sort and bubble sort

Source: Internet
Author: User

# encoding: utf:8l = [5, 6, 9, 11, 34, 66, 6, 8, 7 ]def twopointsearch (L):     for i in range (Len (l)):         min_index = i        for  J in range (I+1, len (L)):     #### #循环判断得出依次次最小直的索引              if l[min_index] > l[j]:                 min_index = j         l[i], l[min_index] = l[min_index], l[i]   ### #l [i]  Minimum value aa    return la = twopointsearch (l) print (a) # # # # Bubble sort ' >>> list ' (range (10,0,-1)) [10, 9, 8, 7, 6, 5, 4, 3,  2, 1] "Def buBble_sort (L):     for i in range (Len (l) -1,0,-1):         for j in range (Len (L)-1):             if l[j] > l[i]:                 l[i],l[j] = l[j],l[i]   ######  l[i]  stored in the cycle of judgment after the maximum straight, the first assignment is the last element     return lb = bubble_sort (l) Print (b)

Output Result:

[5, 6, 6, 7, 8, 9, 11, 34, 66]
[5, 34, 6, 6, 7, 8, 9, 11, 66]

This article is from the "Sky Blue Star" blog, please be sure to keep this source http://jingkonglanxing.blog.51cto.com/1152128/1911575

Python insert sort and bubble sort

Related Article

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.