根据下述二分查找法,在排好序的数组 1,3,6,9,17,31,39,52,61,79,81,90,96 中查找数值 82,和82比较的数组元素分别是( )。
1 int binary_search(vector<int>& nums, int target) { 2 int left = 0; 3 int right = nums.size() - 1; 4 while (left <= right) { 5 int mid = (left + right) / 2; 6 if (nums[mid] == target) { 7 return mid; 8 } else if (nums[mid] < target) { 9 left = mid + 1; 10 } else { 11 right = mid - 1; 12 } 13 } 14 return -1; // 如果找不到目标元素,返回-1 15 }