如果内存不紧缺,你将如何用一种语言来进行排序(该语言可以使用库来表示和排序集合)
c语言sqort函数
代码:
//
the first chapter of programming pearls ,problem two
// files data sort
#include " stdlib.h "
#include " stdio.h "
#include " time.h "
#include " string.h "
#define BITSPEREORD 32 // the type int contains 32 bits
#define SHIFT 5 // pow(2,5)
#define MASK 0X1F // 00011111
#define NUMBER 10000000
int bitBuffer[ NUMBER ];
int intComp ( const void * x , const void * y )
{
return * ( int * )x - * ( int * )y ;
}
int main ()
{
int i = 0 ;
while (scanf( " %d " , & bitBuffer[i]) != EOF )
i ++ ;
qsort(bitBuffer,NUMBER , sizeof ( int ), intComp);
// qsort(
for ( i = 0 ; i < NUMBER ; i ++ )
printf( " %d " ,bitBuffer[i]);
return 0 ;
}
// files data sort
#include " stdlib.h "
#include " stdio.h "
#include " time.h "
#include " string.h "
#define BITSPEREORD 32 // the type int contains 32 bits
#define SHIFT 5 // pow(2,5)
#define MASK 0X1F // 00011111
#define NUMBER 10000000
int bitBuffer[ NUMBER ];
int intComp ( const void * x , const void * y )
{
return * ( int * )x - * ( int * )y ;
}
int main ()
{
int i = 0 ;
while (scanf( " %d " , & bitBuffer[i]) != EOF )
i ++ ;
qsort(bitBuffer,NUMBER , sizeof ( int ), intComp);
// qsort(
for ( i = 0 ; i < NUMBER ; i ++ )
printf( " %d " ,bitBuffer[i]);
return 0 ;
}