/*This is a test*/
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
void main()
{
int n; char c='n';
scanf("%d", &n);
int a[100], find,left=0, right=n-1,mid;
for (int i = 0; i < n; i++)
{
scanf("%d,", &a[i]);
}
scanf("%d", &find);
while (c == 'n')
{
mid = (left + right) / 2;
if (a[mid] == find)
c = 'y';
else if (a[mid] > find)
right = mid-1;
else
left = mid+1;
}printf("%d", mid + 1);
}
C-折半查找
最新推荐文章于 2022-11-03 20:44:43 发布