二分法查找实现(递归与非递归)

#include
#include
#include
#define N 10
using namespace std;

/*顺序查找函数内容*/
int find (int *array, int target){
	for(int i=0;itarget)
			low=mid+1;
		else if(array[mid] high )  
        return -1;  
    int mid = ( low + high )/2;  
    if (array[mid] == target )  
        return mid;  
    else if ( array[mid] < target )  
        return BinarySearchRecursive(array, mid+1, high, target);  
    else  
        return BinarySearchRecursive(array, low, mid-1, target);  
}  

/*打印输出数组内容*/
void print(int *array, int length){
	for(int i=0;ib;
}

int _tmain(int argc, _TCHAR* argv[])
{
	srand((unsigned int)time(NULL));
	int *array=new int[N];
	for(int i=0;i

你可能感兴趣的:(C++)