package com.itjob.algorithm;

public class BinarySearch {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
	}

	/**
	 * 二分查找
	 * @param target
	 * @param array
	 * @return
	 */
	static boolean binarySearch(int target, int[] array){
		int front = 0;
		int tail = array.length - 1;
		
		// 判断子数组是否能再次二分
		while (front <= tail){
			// 获取子数组的中间位置，并依据此中间位置进行二分
			int middle = (front + tail) / 2;
			
			if (array[middle] == target){
				return true;
			}
			else if (array[middle] > target){
				tail = middle - 1;
			}
			else{
				front = middle + 1;
			}
		}
		return false;
	}
}
