2. Various sorting algorithms and program sorting algorithms in the program

Source: Internet
Author: User

2. Various sorting algorithms and program sorting algorithms in the program

1. Bubble Sorting

The Bubble Sorting Algorithm operates as follows:

(1) Compare adjacent numbers in ascending order or ascending order,

(2) after such a trip, the largest or smallest number is exchanged to the last digit,

(3) then compare and exchange data from the beginning until the last and second digits.

The average time complexity of Bubble Sorting is

1 void bubble_sort (int a [], int n) 2 {3 int I, j, temp; 4 for (j = 0; j <n-1; j ++) 5 {6 for (I = 0; I <n-1-j; I ++) 7 {8 if (a [I]> a [I + 1]) 9 {10 temp = a [I]; 11 a [I] = a [I + 1]; 12 a [I + 1] = temp; 13} 14} 15} 16}
View Code

2. Quick sorting

 

3. Insert sorting

 

4. Hill sorting

 

5. Select sorting

 

6. Merge and 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.