摘要: 看到一篇文章《Extra, Extra - Read All About It: Nearly All Binary Searches and Mergesorts are Broken》说的是很多二分查找都有bug,包括《编程珠玑》上给出的实现。这个bug也曾经出现在java.util中。典型的Java版实现是int binarySearch(int a[], int key, int length) { int low = 0; int high = length - 1; while (low <= high) { int mid = (low + high) / 2; int m 阅读全文
posted @ 2012-02-19 09:19 westfly 阅读(497) 评论(0) 推荐(0) 编辑