From 8938c3447d88e31f77f20553ed185fc8e64c9ac8 Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 22 Jun 2021 14:58:53 +0800 Subject: +misc --- Assets/Algorithms/Searching.cs | 35 ----------------------------------- 1 file changed, 35 deletions(-) delete mode 100644 Assets/Algorithms/Searching.cs (limited to 'Assets/Algorithms/Searching.cs') 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[] dataList, T value) where T : IComparable, IEquatable - { - 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 -- cgit v1.1-26-g67d0