diff options
author | chai <chaifix@163.com> | 2021-06-22 14:58:53 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-06-22 14:58:53 +0800 |
commit | 8938c3447d88e31f77f20553ed185fc8e64c9ac8 (patch) | |
tree | 0b13d53b203323891826a600febfe4e90c991a36 /Assets/Algorithms/Searching.cs | |
parent | 5d81d8d8b4062def695c27fa02f67625871e8dce (diff) |
+misc
Diffstat (limited to 'Assets/Algorithms/Searching.cs')
-rw-r--r-- | Assets/Algorithms/Searching.cs | 35 |
1 files changed, 0 insertions, 35 deletions
diff --git a/Assets/Algorithms/Searching.cs b/Assets/Algorithms/Searching.cs deleted file mode 100644 index 3489eac..0000000 --- a/Assets/Algorithms/Searching.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System;
-using System.Collections;
-using System.Collections.Generic;
-using AlgorithmCollection;
-
-namespace AlgorithmCollection.Searching
-{
-
- public static class SearchingHelper
- {
-
- // 二分搜索,返回索引号
- // O(logn)
- public static int BinarySearch<T>(T[] dataList, T value) where T : IComparable, IEquatable<T>
- {
- int n = dataList.Length;
- int left = 0;
- int right = n - 1;
- while(left <= right)
- {
- int middle = (right + left) / 2;
- T midValue = dataList[middle];
- if (value.Equals(midValue))
- return middle;
- if (value.CompareTo(midValue) > 0)
- left = middle + 1;
- if (value.CompareTo(midValue) < 0)
- right = middle - 1;
- }
- return -1; // 没找到
- }
-
- }
-
-}
\ No newline at end of file |