C言語なら、俺に聞け! <23>
■ このスレッドは過去ログ倉庫に格納されています
0554546
NGNG#include <stdio.h>
#include <stdlib.h>
typedef struct{
int nedan;
int kosuu;
int syurui;
int uribi;
} KOU;
KOU kou[10];
#define NELEM(x) (sizeof(x) / sizeof(x[0]))
#define CMP_FUNC(obj_) \
static int \
cmp_by_##obj_(const void *p1, const void *p2) \
{ \
const KOU* q1 = p1; \
const KOU* q2 = p2; \
return q1->obj_ - q2->obj_; \
}
CMP_FUNC(nedan)
CMP_FUNC(kosuu)
CMP_FUNC(syurui)
CMP_FUNC(uribi)
static int (*cmpfunc[])(const void *, const void *) =
{
cmp_by_nedan,
cmp_by_kosuu,
cmp_by_syurui,
cmp_by_uribi,
};
void
kou_sort(int sorter)
{
qsort(kou, NELEM(kou), sizeof(kou[0]), cmpfunc[sorter]);
}
■ このスレッドは過去ログ倉庫に格納されています