#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void swap(int *p1, int *p2)
{
int tmp = 0;
tmp = *p1;
*p1 = *p2;
*p2 = tmp;
}
void quick_sort(int arr[], int len)
{
int i = 0;
int j = 0;
for (i = 0; i < len; i++)
{
for (j = 0; j < len-1-i; j++)
{
if (arr[j]>arr[j + 1])
swap(&arr[j], &arr[j + 1]);
}
}
}
int main()
{
int i = 0;
int arr[] = {1,3,5,7,9,2,4,6,8,10};
int len = sizeof(arr) / sizeof(arr[0]);
quick_sort(arr, len);
for (i = 0; i < len; i++)
{
printf("%d ", arr[i]);
}
printf("\n");
system("pause");
return 0;
}
本文转自 七十七快 51CTO博客,原文链接:http://blog.51cto.com/10324228/1689067