算法学习笔记之二分查找函数

/*
 * main.c
 *
 *  Created on: Oct 29, 2010
 *      Author: jenson
 */

#include <stdio.h>
#include <stdlib.h>

int cmp(const void *ch,const void *s);

int main(){
    char ch;
    char *p;
    printf("Enter a character:");
    ch = getchar();
    ch = tolower(ch);
    p = (char *)bsearch(&ch,"abcdefghijklmnopqrstuvwxyz",26,1,cmp);
    if(p){
        printf("%c is found\n",ch);
    }else{
        printf("%c is not found.\n",ch);
    }
    return 0;
}
int cmp(const void *ch,const void *s){
    return *(char *)ch - *(char *)s;
}

你可能感兴趣的:(算法,职场,休闲)