python-Bubble Sort

Source: Internet
Author: User

Bubble sort : Sorts an irregular array in order from small to large

One of the core ideas in bubble sequencing is:

From the first number to the last number, compare two adjacent numbers each time, and if they are in the wrong order, swap them in place. This will put the biggest number at the end.

Then continue from the first number to the second-to-last number, each time comparing two adjacent numbers, if they are in an incorrect order, then swap positions, so that the second-to-last number of large numbers in the penultimate position

etc...

data = [6, 5, one, one, one, one, one, 2]for J in range (1,len (data)): A for    I in range (len (data)-j):        if data[i] > data [i+1]:            tmp = data[i+1]            data[i+1] = Data[i]            data[i] = tmpprint (data)

  

python-Bubble 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.