C language implementation of common sorting

Source: Internet
Author: User

C language implementation of common sorting

Void BubbleSort (int R [], int n) // bubble sort time complexity O (n2) {int I, j, temp, flag; for (I = n; i> = 2; I --) {flag = 0; for (j = 2; j <= I; j ++) {if (R [J-1]> R [j]) {temp = R [J-1]; R [J-1] = R [j]; R [j] = temp; flag = 1 ;}}if (flag = 0) {return ;}} void InsertSort (int R [], int n) // directly Insert the sorting time complexity O (n2) {int I, j, temp; for (I = 2; I <= n; I ++) {temp = R [I]; j = I-1; while (j> = 1 & R [j]> temp) {R [j + 1] = R [j]; j --;} R [j + 1] = temp;} void QuikSort (int R [], int l, int r) // fast schedule complexity O (nlogn) {int I, j, temp; I = l; j = r; if (l
 
  
I & R [j]> temp) -- j; // searches for the next value less than temp in reverse order and exchanges it with R [I] if (I
  
   

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.