交换排序:冒泡排序,快速排序
快速排序:
解释说明:
稳定性:冒泡排序是不稳定的
时间复杂度: ![T(n) = O(==![nlogn](https://img-blog.csdnimg.cn/20181103094626317.png)==)](https://i-blog.csdnimg.cn/blog_migrate/a297086d1d6ffa0cf126c2ed171a107c.png)
快速排序不适合对小规模的序列进行排序
代码:
#include <stdio.h>
#include <stdlib.h>
void QuickSort(int a[],int low,int high){
int i,j,pivot,temp;
if(low < high){
pivot = a[low];
for(j = low,i = low + 1;i <= high;i++)
if(pivot >= a[i]){
temp = a[i],a[i] = a[j + 1],a[j + 1] = temp;
temp = a[j],a[j] = a[j + 1],a[j + 1] = temp;
j++;
}
QuickSort(a,low,j - 1);
QuickSort(a,j + 1,high);
}
}
int main()
{
int a[10] = {6,4,7,2,5,8,3,1,9,10},i;
QuickSort(a,0,9);
for(i = 0;i < 10;i++)
printf("%d ",a[i]);
return 0;
}