public static int binarySearch(int[] array, int num, int low, int high,
			boolean searchFirst) {

		if (low > high) {
			return -1;
		} else {
			int mid = (low + high) / 2;
			if (searchFirst) {
				if (num == array[mid] && num != array[mid - 1])
					return mid;
				else if (num > array[mid]) {
					return binarySearch(array, num, mid + 1, high, searchFirst);
				}
				return binarySearch(array, num, low, mid - 1, searchFirst);
			} else {
				if (num == array[mid] && num != array[mid + 1])
					return mid;
				else if (num < array[mid]) {
					return binarySearch(array, num, low, mid - 1, searchFirst);
				}
				return binarySearch(array, num, mid + 1, high, searchFirst);
			}
		}
	}