美容プログラミングC ++ - (エラーのリスト3-17(バイナリ検索元))法の構造を

(バイナリ検索元の誤差で)3-17リスト

int bisearch(char** arr, int b, int e, char* v)
{
     int minIndex = b, maxIndex = e, midIndex;
     while(minIndex < maxIndex)
     {
          midIndex = (minIndex + maxIndex) / 2;
          if(strcmp(arr[midIndex], v) <= 0)
          {
               minIndex = midIndex;
          }
          else
          {
               maxIndex = midIndex – 1;
          }
     }
     if(!strcmp(arr[maxIndex], v))
     {
          return maxIndex;
     }
     else
     {
          return -1;
     }
}
リリース1246元の記事 ウォンの賞賛951 ビュー70000 +

おすすめ

転載: blog.csdn.net/weixin_42528266/article/details/104028171