#include <stdio.h> #include <stdlib.h> // 集成最快排序与查找 #define NUM 8 int compare(const void *p, const void *q) { return (*(int *)p - *(int *)q); } int main(int argc, char *argv[]) { int array[NUM] = {9, 2, 7, 11, 3, 87, 34, 6}; int key; scanf("%d",&key); int *p; qsort(array, NUM, sizeof(int), compare); p = (int *)bsearch(&key, array, NUM, sizeof(int), compare); (p == NULL) ? puts("not found") : puts("found"); return 0; }
原文:http://www.cnblogs.com/xzenith/p/3632746.html