/**
 *折半查找
 */

#include <stdio.h>
#include <stdlib.h>

#define MAX_LENGTH 10

int init_arrary[MAX_LENGTH];

void findGetNumber(int key)
{
	int i=0;
	int mid;
	int low = 0;
	int height = 0;

	int length = MAX_LENGTH;
	height  = length;

	while(low<=height)
	{
		mid = (height+low)/2;
		printf("init_arrary[mid]= %d\n",init_arrary[mid]);
		if(init_arrary[mid] == key)
		{
			i = mid;
			printf("--------------------find mid %d\n",mid);
			break;
		}
		else if(init_arrary[mid]>key)
		{
			height = mid-1;


		}
		else if(init_arrary[mid]<key)
		{
			low = mid+1;
		}
		printf("low=%d\t height=%d\n",low,height);
	}

	return i;
}

int main()
{
	int i = 0;
	for(i=0;i<10;i++)
	{
		init_arrary[i] = i*i;
		printf("%d\n",init_arrary[i]);
	}
	
	findGetNumber(81);	
	
	getchar();
}