⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 binary.c

📁 Object-Oriented Programming With ANSI-C这本书中的源代码!找了很久
💻 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 + -