#include <iostream>
#include <cstdlib>
using namespace std;
const size_t INDEX_ZERO = 0;
int com(const void *a,const void *b)
{
return *(int*)a - *(int*)b;
}
void display( const int* array, size_t size )
{
if (NULL == array)
{
throw;
}
else
{
for(size_t i=INDEX_ZERO; i<size; ++i)
{
cout << array[i] << " ";
}
cout << endl;
}
}
int main( void )
{
int array[] = {9, 1, 7, 3, 4, 8, 2, 6, 0, 5};
const size_t SIZE = sizeof (array) / sizeof (*array);
display( array, SIZE );
qsort(array, SIZE, sizeof (*array), com);//C标准库中的快速排序(quick-sort)函数
display( array, SIZE );
system( "PAUSE" );
return EXIT_SUCCESS;
}
/*-------------------
9 1 7 3 4 8 2 6 0 5
0 1 2 3 4 5 6 7 8 9
请按任意键继续. . .
---------------------------------*/
C标准库中的快速排序(quick-sort)函数 [简单应用]
最新推荐文章于 2024-03-29 15:31:23 发布