- class BinarySearch
- {
- public int search(int[] A, int p, int q, int key)
- {
- int result = -1;
- if (p >= q && key == A[p])
- {
- result = p;
- }
- else
- {
- int k = (p+q)/2;
- if (key == A[k])
- result = k;
- else
- result = (key < A[k]) ? search(A, p, k-1, key) :
- search(A, k+1, q, key);
- }
- return result;
- }
C#二分搜索算法
最新推荐文章于 2022-09-07 20:19:22 发布