📄 binary.c
字号:
/* * binary() * search and maintain a sorted array */#include <string.h>#include "binary.h"void * binary (const void * key, void * _base, size_t * nelp, size_t width, int (* cmp) (const void * key, const void * elt)){ size_t nel = * nelp;#define base (* (char **) & _base) char * lim = base + nel * width, * high; if (nel > 0) { for (high = lim - width; base <= high; nel >>= 1) { char * mid = base + (nel >> 1) * width; int c = cmp(key, mid); if (c < 0) high = mid - width; else if (c > 0) base = mid + width, -- nel; else return (void *) mid; } memmove(base + width, base, lim - base); } ++ *nelp; return memcpy(base, key, width);#undef base}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -