摘要:参见编程珠玑chap4 chap9,和编程之美3.3给定一个有序(不降序)数组arr,,求任意一个i使得arr[i]等于t,不存在返回-1不变式:x[low]< =t<=x[high]int biSearch(int *arr, int low, int high, int t){ int mid; while(low<=high) { mid=low+(high-low)/2; if(arr[mid]==t) { return mid; } else if(arr[mid]>t) ...
阅读全文
随笔分类 - 笔经
摘要:字符串比较函数,这个函数也比较常用:view plaincopy to clipboardprint?int strcmp(const char* str1,const char* str2){ assert(str1!=NULL&&str2!=NULL); while(*str1&&*str2&&*str1==*str2){ str1++; str2++; } if(*str1==*str2&&*str1==0) return 0;//equal else if(*str1...
阅读全文

浙公网安备 33010602011771号