最小二分法查找算法[c 非递归]

int BinarySearch(int key)
{
int left; //left var
int right; //right var
int middle;
left = 0;
right = MAX-1; //MAX is the number of array members
while(left <= right)
{
middle = (left+right)/2;
if(key < Data[middle])
right = middle -1;
else if (key > Data[middle])
left = middle+1;
else if (key == Data[middle])
printf("Find it! Data[%d] \n",middle)
return 1; //1 means succes
}
}

你可能感兴趣的:(C++,c,算法,C#)