//BinarySearch.cpp
//purpose: Find easily in a sorted array
//djg 2010-05-20
//
//¶þ·Ö²éÕÒËã·¨
//
int BinarySearch(array& a, int key)
{
	int low = 0;
	int high = a.getSize()- 1;
	while (low <= high) 
	{
		int mid = low + ((high - low) / 2);
		int midVal = a[mid];
		if (midVal < key)
			low = mid + 1;
		else if (midVal > key)
			high = mid - 1;
		else
		return mid; // key found
	}
	return -(low + 1);  // key not found.
}
