|
| #include <stdio.h>
#include <stdlib.h>
int compare( const void *arg1, const void *arg2 );
int main()
{
int a[10] = {5,2,3,8,1};
qsort( a, 5, 4, compare );
int i;
for( i = 0; i < 5; i++ ) {
printf( "%d\n", a[i] );
}
return 0;
}
int compare( const void *arg1, const void *arg2 )
{
int nRet;
if ( (*(int *)arg1) == (*(int *)arg2) ) {
nRet = 0;
}
if ( (*(int *)arg1) < (*(int *)arg2) ) {
nRet = -1;
}
if ( (*(int *)arg1) > (*(int *)arg2) ) {
nRet = 1;
}
return nRet;
}
| |
|
|
|
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int compare( const void *arg1, const void *arg2 );
int main()
{
char *a[10];
char buff[80] = "ZZZ,AAA,NNN,OOO,555,???";
int idx,pos,len;
a[0] = buff;
pos = 1;
len = strlen( buff );
for( idx = 0; idx < len; idx++ ) {
// ここにコードを記述
}
qsort( 引数を記述 );
int i;
for( i = 0; i < 6; i++ ) {
printf( "%s\n", a[i] );
}
return 0;
}
int compare( const void *arg1, const void *arg2 )
{
int nRet;
// ここにコードを記述
return nRet;
}
| |
|
|
|