| [ CnUnix ] in KIDS 글 쓴 이(By): ahsarang (.아.사.랑.) 날 짜 (Date): 2002년 10월 15일 화요일 오후 11시 29분 42초 제 목(Title): Re: sort 문제 질문: 만만할까요? 비교함수만. 소팅은 알아서... :) int cmp_yarikkuri(const char *a, const char *b); --- 여부터 --- static float to_float(const char *s) { char a[100]; char pa = a; float f; strcpy(a, s); while (*pa) { if (*pa == '_') { *pa = '.'; } pa++; } sscanf(a, "%f", &f); return f; } static int cmp_float(float a, float b) { float f = a - b; if (f > 0) return 1; else if (f < 0) return -1; return 0; } int cmp_yarikkuri(const char *a, const char *b) { if (a[0] == '+') { if (b[0] == '+') { return cmp_float(to_float(a), to_float(b)); } return 1; } else if (a[0] == '-') { if (b[0] == '-') { return cmp_float(to_float(a), to_float(b)); } return -1; } if (b[0] == '+') { return -1; } else (b[0] == '-') { return 1; } return cmp_float(to_float(a), to_float(b)); } ---- 여까지... --- |