nmap
全部博文(3)
2009年(1)
2008年(2)
分类: C/C++
2009-05-10 12:57:20
/* binsearch: find x in v[0] <= v[1] <= .. <= v[n-1] */ int binsearch(int x, int v[], int n) { int low, high, mid; low = 0; high = n - 1; while (low <= high) { mid = (low+high)/2; if (x < v[mid]) high = mid + 1; else if (x > v[mid]) low = mid + 1; else /* found match */ return mid; } return -1; /* no match */ }
/* binsearch: find x in v[0] <= v[1] <= .. <= v[n-1] */ int binsearch(int x, int v[], int n) { int low, high, mid; low = 0; high = n - 1; while (low <= high) { mid = (low+high)/2; if (x < v[mid]) high = mid - 1; else if (x > v[mid]) low = mid + 1; else /* found match */ return mid; } return -1; /* no match */ }
上一篇:初解《Compiler Construction Principle and Practice》习题
下一篇:没有了
nmap2010-05-01 11:18:52
哦,多谢了,扫描版的电子书有时候不清楚。
chinaunix网友2010-02-24 19:06:56
应该是电子版书的问题,实体书没这个问题呢。。
登录 注册