#include "compare.h" #include #include int fcmp_int(const void *x, const void *y) { if (*(const int *)x < *(const int *)y) { return -1; } else if (*(const int *)x > *(const int *)y) { return 1; } else { return 0; } } int fcmp_reverse_int(const void *x, const void *y) { return fcmp_int(y, x); } int fcmp_char(const void *x, const void *y) { if(*(const char *)x < *(const char *)y) { return -1; } else if(*(const char *)x > *(const char *)y) { return 1; } else { return 0; } } int fcmp_double(const void *x, const void *y) { if (*(const double *)x < *(const double *)y) { return -1; } else if (*(const double *)x > *(const double *)y) { return 1; } else { return 0; } } int fcmp_string(const void *x, const void *y) { int r = fcmp_char(x, y); if(r != 0) return r; return fcmp_char((const char *)x+1, (const char *)y+1); } int fcmp_string_hiera(const void *x, const void *y) { if (strlen(*(const string *)x) < strlen(*(const string *)y)) { return -1; } else if (strlen(*(const string *)x) > strlen(*(const string *)y)) { return 1; } else { return 0; } } int fcmp_pointx(const void *p, const void *q) { const point *pp = p; const point *qq = p; return fcmp_double((const void *)&(pp->x), (const void *)&(qq->x)); } int fcmp_pointy(const void *p, const void *q) { const point *pp = p; const point *qq = p; return fcmp_double((const void *)&(pp->y), (const void *)&(qq->y)); }