Using Python for bubbling sorting

Source: Internet
Author: User

1. Live a list of random numbers first

2, then to sort, put the big elements in the back, small elements placed in front, the final realization from small to large arrangement

First to survive a list of random numbers

Import random# Print (Sys.path) # print (__file__) L1 = []for i in range (6):    i = Random.randrange (0,165535)    L1.append (i) print (L1) [72764, 163851, 54255, 51053, 106289, 48579]

Then sort the list

r = Len (L1) for M in Range (r-1):    a = 0 for    n in range (r-1):        if l1[a] > l1[a + 1]:             Tmp_before = l1[a]
   
    tmp_after = l1[a + 1]             l1[a] = tmp_after             l1[a + 1] = Tmp_before             # print (L1)        elif l1[a] = = L1[a + 1]:            s = "l1[%s] and l1[%s] equal, this time without replacing"% (a,a+1)            print (S.center (+, "-"))            pass        else:            s = "l1[%s" is smaller than l1[%s], This time without replacing "% (a, a + 1)            print (S.center (+,"-"))            pass        A + = 1print (L1) [48579, 51053, 54255, 72764, 106289, 16385 1]
   

Using Python for bubbling sorting

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.