# C语言基础入门知识——排序

void bulletSort(int arr[], int len)//冒泡排序

{

int temp = 0;//作为交换的中间变量

for (int i = 0; i

{

for (int j = 0; j

{

if (arr[j]>arr[j + 1])

{

temp = arr[j+1];

arr[j + 1] = arr[j];

arr[j] = temp;

}

}

}

}

void selectSort(int arr[], int len)

{

int min;

int temp = 0;

for (int i = 0; i

{

min = i;

for (int j = i + 1; j

{

if (arr[j]

min = j;

}

temp = arr[i];

arr[i] = arr[min];

arr[min] = temp;

}

}

void insertSort(int arr[], int len)

{

int temp = 0;

int j = 0;

for (int i = 1; i

{

j = i - 1;

temp = arr[i];

while(j >= 0 && arr[j]>temp)

{

arr[j+1] = arr[j];

j--;

}

arr[j + 1] = temp;

}

}

void quickSort(int arr[], int left, int right)

{

if (left >= right)return;

int i = left, j = right, temp;

while (i

{

while (i

j--;

while (i=arr[i])

i++;

if (i

{

temp = arr[i];

arr[i] = arr[j];

arr[j] = temp;

}

}

//跳出循环则说明i==j

temp = arr[left];

arr[left] = arr[i];

arr[i] = temp;

quickSort(arr, left, i - 1);

quickSort(arr, i+1, right);

}

• 发表于:
• 原文链接https://kuaibao.qq.com/s/20191014A0PUME00?refer=cp_1026
• 腾讯「云+社区」是腾讯内容开放平台帐号（企鹅号）传播渠道之一，根据《腾讯内容开放平台服务协议》转载发布内容。
• 如有侵权，请联系 yunjia_community@tencent.com 删除。

2019-10-08

2019-10-08

2019-10-08

2019-09-26