最小二分法查找算法[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

}

}

    原文作者:查找算法
    原文地址: https://blog.csdn.net/iteye_15968/article/details/81311598
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞