二分查找
Posted 霏霏暮雨
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了二分查找相关的知识,希望对你有一定的参考价值。
int binarysearch(int arry[], int n, int goal) { int low = -1; int high = n; while(low + 1 < high) { int mid = (low + high) >> 1; if(arry[mid] < goal) { low = mid; } else { high = mid; } } int value = high; if(high >= n || arry[high] != goal) value = -1; cout<<"low is "<<low<<",high is "<<high<<",value is "<<value<<endl; return 0; }
以上是关于二分查找的主要内容,如果未能解决你的问题,请参考以下文章