#include<stdio.h>
int FindValue(int* br, int n, int val)
{
int pos = -1;
if (br == nullptr || n < 1) return pos;
int left = 0, right = n - 1;
while (left <= right)
{
int mid = (right + left) / 2;
if (val < br[mid])
{
right = mid - 1;
}
else if (val > br[mid])
{
left = mid + 1;
}
else
{
pos = mid;
break;
}
}
return pos;
}
int main()
{
const int n = 10;
int ar[n] = { 12,23,34,45,56,67,78,89,90,100 };
for (int i=0;i < n;++i)
{
int pos = FindValue(ar,n,ar[i]);
printf("%d=>%d\n", ar[i], pos);
}
return 0;
}
今天主要讲了之前的作业和练习。