EricYang

Tech Spot of Eric

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

随笔分类 -  笔经

摘要:参见编程珠玑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) ... 阅读全文
posted @ 2012-08-17 16:16 Eric-Yang 阅读(206) 评论(0) 推荐(0)

摘要:字符串比较函数,这个函数也比较常用: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... 阅读全文
posted @ 2012-08-15 23:17 Eric-Yang 阅读(784) 评论(0) 推荐(0)