日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

C#二分查找算法_C#教程

作者:農碼一生 ? 更新時間: 2022-06-28 編程語言

1、定義:

折半搜索,也稱二分查找算法、二分搜索,是一種在有序數組中查找某一特定元素的搜索算法。

要計算把目標值插入到該數組中的索引值。最開始的思路:

①.先把目標數插入到數組中

②.進行排序

③.返回索引

2、實現代碼:

  public static int process4(int[] arr, int low, int high, int key)
  {
    int mid = (low + high) / 2;
    if (low > high)
      return -1;
    else
    {
      if (arr[mid] == key)
        return mid;
      else if (arr[mid] > key)
        return process4(arr, low, mid - 1, key);
      else
        return process4(arr, mid + 1, high, key);
    }
  }

原文鏈接:https://www.cnblogs.com/wml-it/p/16048142.html

欄目分類
最近更新