http://www.programmer-club.com.tw/ShowSameTitleN/evc/1937.html
[code]
void * __cdecl bsearch ( const void *key, const void *base, size_t num, size_t width, int (__cdecl *compare)(const void *, const void *) );
[/code]
[code]
void * __cdecl bsearch ( const void *key, const void *base, size_t num, size_t width, int (__cdecl *compare)(const void *, const void *) )
{
char *lo = (char *)base;
char *hi = (char *)base + (num - 1) * width;
char *mid;
unsigned int half;
int result;
while (lo <= hi)
if (half = num / 2)
{
mid = lo + (num & 1 ? half : (half - 1)) * width;
if (!(result = (*compare)(key,mid)))
return(mid);
else if (result < 0)
{
hi = mid - width;
num = num & 1 ? half : half-1;
}
else {
lo = mid + width;
num = half;
}
}
else if (num)
return((*compare)(key,lo) ? NULL : lo);
else
break;
return(NULL);
}
[/code]
[code]
void * __cdecl bsearch ( const void *key, const void *base, size_t num, size_t width, int (__cdecl *compare)(const void *, const void *) );
[/code]
[code]
void * __cdecl bsearch ( const void *key, const void *base, size_t num, size_t width, int (__cdecl *compare)(const void *, const void *) )
{
char *lo = (char *)base;
char *hi = (char *)base + (num - 1) * width;
char *mid;
unsigned int half;
int result;
while (lo <= hi)
if (half = num / 2)
{
mid = lo + (num & 1 ? half : (half - 1)) * width;
if (!(result = (*compare)(key,mid)))
return(mid);
else if (result < 0)
{
hi = mid - width;
num = num & 1 ? half : half-1;
}
else {
lo = mid + width;
num = half;
}
}
else if (num)
return((*compare)(key,lo) ? NULL : lo);
else
break;
return(NULL);
}
[/code]
'Windows > MFC' 카테고리의 다른 글
프로그램의 게시자를 알 수 없습니다 (0) | 2013.10.02 |
---|---|
exif CExifManager (0) | 2013.10.02 |
C2065 sprintf_instead_use_StringCbPrintfA_or_StringCchPrintfA (0) | 2013.10.02 |
Windows Mobile 5 Colors (0) | 2013.10.02 |
Pocket PC Theme Generator Power Toy 2.0 (0) | 2013.10.02 |