二分搜索

Template 
int binarySearch(Type a[] , const T&x , int left , int right , int &i , int &j)
{
      int middle;
      while(left <= right)
        {
              middle = (left + right) / 2;
              if(x == a[middle])
              {
                  i = j =middle;
                  return 1;
              }
              if(x < a[middle]) right = middle - 1;
              else   left = middle + 1;
        }
      return 0 ;
}

你可能感兴趣的:(二分搜索)