Visitors hit counter dreamweaver
摘要: 二分查找时在给定已按升序排好序的n个元素a[0:n-1],用折半查找法在从这n个元素中找出一特定元素x,时间复杂性为O(logn)。 具体实现如下://二分查找static int binarySearch(int []a, int x, int n){ int left = 0,right = n-1; int middle; while (left <= right) { middle = (left+right)/2; if (x == a[middle]) return middle; if (x > a[mid... 阅读全文
posted @ 2013-06-01 22:07 Jason Damon 阅读(3607) 评论(0) 推荐(1) 编辑