排序算法
1 插入排序
a.直接插入
b.希尔排序
2 选择排序
a.直接选择排序
b.堆排序
3. 交换排序
a.冒泡
b.快速排序
#include
int partition(int a[], int low, int high)
{
int standard = a[low];
int i=low;
int j=high;
while(i
while(a[j]>standard && i
while(a[i]
}
a[i] = standard;
return i;
}
void quick_sort(int a[], int low, int high)
{
int position;
if(low
position = partition(a, low, high);
quick_sort(a, low, position-1);
quick_sort(a, position+1, high);
}
}
void print(const int a[], int n)
{
int i;
for(i=0;i
printf("\n");
}
int main(int argc, char *argv[])
{
int a[] = {2, 34, 1, 234, 31, 23, 98};
print(a, 7);
quick_sort(a, 0, 7);
print(a, 7);
system("pause");
return 0;
}