diff options
author | chai <chaifix@163.com> | 2021-06-24 19:55:26 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-06-24 19:55:26 +0800 |
commit | dbcd0c269014100b7d4cc421c5ab518f275cca09 (patch) | |
tree | 6564ca8a58b6921d4782bba3feae0ea787f9e1f4 /Assets/Algorithms | |
parent | 2749e059084b99737d79aadd92521023b0f65f56 (diff) |
Diffstat (limited to 'Assets/Algorithms')
-rw-r--r-- | Assets/Algorithms/Algebra/Linear.cs | 13 | ||||
-rw-r--r-- | Assets/Algorithms/Algebra/MatrixUtils.cs | 13 | ||||
-rw-r--r-- | Assets/Algorithms/Algebra/MatrixUtils.cs.meta | 11 | ||||
-rw-r--r-- | Assets/Algorithms/Algebra/Vector3Utils.cs | 13 | ||||
-rw-r--r-- | Assets/Algorithms/Algebra/Vector3Utils.cs.meta | 11 | ||||
-rw-r--r-- | Assets/Algorithms/Algorithms.cs | 13 | ||||
-rw-r--r-- | Assets/Algorithms/Algorithms_Utils.cs | 31 | ||||
-rw-r--r-- | Assets/Algorithms/Algorithms_Utils.cs.meta | 11 | ||||
-rw-r--r-- | Assets/Algorithms/Geometry/GeometryHelper.cs | 19 | ||||
-rw-r--r-- | Assets/Algorithms/PathFinding/AStarPathfinding.cs | 31 | ||||
-rw-r--r-- | Assets/Algorithms/PathFinding/DijkstraPathfinding.cs | 13 | ||||
-rw-r--r-- | Assets/Algorithms/PathFinding/DijkstraPathfinding.cs.meta | 11 | ||||
-rw-r--r-- | Assets/Algorithms/Recursion/Recursion_DP.cs | 2 | ||||
-rw-r--r-- | Assets/Algorithms/Recursion/Recursion_Greedy.cs | 15 | ||||
-rw-r--r-- | Assets/Algorithms/Recursion/Recursion_Greedy.cs.meta | 11 | ||||
-rw-r--r-- | Assets/Algorithms/Searching/SearchingHelper.cs | 4 |
16 files changed, 183 insertions, 39 deletions
diff --git a/Assets/Algorithms/Algebra/Linear.cs b/Assets/Algorithms/Algebra/Linear.cs index 5448b50..29584ce 100644 --- a/Assets/Algorithms/Algebra/Linear.cs +++ b/Assets/Algorithms/Algebra/Linear.cs @@ -2,17 +2,12 @@ using System.Collections.Generic;
using UnityEngine;
-public class Linear : MonoBehaviour
+
+namespace AlgorithmCollection.Algebra
{
- // Start is called before the first frame update
- void Start()
+ public static class Linear
{
-
- }
- // Update is called once per frame
- void Update()
- {
-
+
}
}
diff --git a/Assets/Algorithms/Algebra/MatrixUtils.cs b/Assets/Algorithms/Algebra/MatrixUtils.cs new file mode 100644 index 0000000..84c12c3 --- /dev/null +++ b/Assets/Algorithms/Algebra/MatrixUtils.cs @@ -0,0 +1,13 @@ +using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+
+namespace AlgorithmCollection.Algebra
+{
+ public static class MatrixUtils
+ {
+
+
+ }
+}
diff --git a/Assets/Algorithms/Algebra/MatrixUtils.cs.meta b/Assets/Algorithms/Algebra/MatrixUtils.cs.meta new file mode 100644 index 0000000..1ac378e --- /dev/null +++ b/Assets/Algorithms/Algebra/MatrixUtils.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bb506f4381cf42643a1d968c52ec0bae +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Algorithms/Algebra/Vector3Utils.cs b/Assets/Algorithms/Algebra/Vector3Utils.cs new file mode 100644 index 0000000..d77030f --- /dev/null +++ b/Assets/Algorithms/Algebra/Vector3Utils.cs @@ -0,0 +1,13 @@ +using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+
+namespace AlgorithmCollection.Algebra
+{
+ public static class Vector3Utils
+ {
+
+
+ }
+}
diff --git a/Assets/Algorithms/Algebra/Vector3Utils.cs.meta b/Assets/Algorithms/Algebra/Vector3Utils.cs.meta new file mode 100644 index 0000000..856cdea --- /dev/null +++ b/Assets/Algorithms/Algebra/Vector3Utils.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5550f49c26a0d8e4c8d014b7e7b530a5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Algorithms/Algorithms.cs b/Assets/Algorithms/Algorithms.cs index a6005d3..7d51606 100644 --- a/Assets/Algorithms/Algorithms.cs +++ b/Assets/Algorithms/Algorithms.cs @@ -49,10 +49,21 @@ namespace AlgorithmCollection return v1.CompareTo(v2) < 0 ? v1 : v2;
}
+ public static T Max<T>(T v1, T v2) where T : IComparable
+ {
+ return v1.CompareTo(v2) > 0 ? v1 : v2;
+ }
+
public static string ListToString<T>(List<T> data)
{
string content = "";
- data.ForEach((T v) => { content += v.ToString(); });
+ //data.ForEach((T v) => { content += v.ToString(); });
+ for(int i = 0; i < data.Count; ++i)
+ {
+ content += data[i];
+ if (i != data.Count - 1)
+ content += ",";
+ }
return content;
}
diff --git a/Assets/Algorithms/Algorithms_Utils.cs b/Assets/Algorithms/Algorithms_Utils.cs new file mode 100644 index 0000000..6eee42f --- /dev/null +++ b/Assets/Algorithms/Algorithms_Utils.cs @@ -0,0 +1,31 @@ +using System;
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace AlgorithmCollection
+{
+ public static partial class Algorithms
+ {
+ // 两数之和,在nums中找到和为target的两个数
+ public static int[] TwoSum(int[] nums, int target)
+ {
+ int a = 0, b = 0;
+ Dictionary<int, int> lut = new Dictionary<int, int>();
+ for (int i = 0; i < nums.Length; ++i)
+ {
+ if (lut.ContainsKey(target - nums[i]))
+ {
+ a = i;
+ b = lut[target - nums[i]];
+ break;
+ }
+ lut.Add(nums[i], i);
+ }
+ return new int[] { a, b };
+ }
+
+ //
+
+ }
+}
\ No newline at end of file diff --git a/Assets/Algorithms/Algorithms_Utils.cs.meta b/Assets/Algorithms/Algorithms_Utils.cs.meta new file mode 100644 index 0000000..350781c --- /dev/null +++ b/Assets/Algorithms/Algorithms_Utils.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 325a82332ec4d724685daa5e2e076443 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Algorithms/Geometry/GeometryHelper.cs b/Assets/Algorithms/Geometry/GeometryHelper.cs index 6da1503..da74944 100644 --- a/Assets/Algorithms/Geometry/GeometryHelper.cs +++ b/Assets/Algorithms/Geometry/GeometryHelper.cs @@ -2,17 +2,18 @@ using System.Collections.Generic;
using UnityEngine;
-public class GeometryHelper : MonoBehaviour
+
+namespace AlgorithmCollection.Geometry
{
- // Start is called before the first frame update
- void Start()
+ public static class GeometryHelper
{
-
- }
- // Update is called once per frame
- void Update()
- {
-
+ // 多边形最佳剖分,将多边形划分为权重最小的三角形
+ public delegate int SubdivisionWeight(int v1, int v2, int v3);
+ public static void SubdividePolygon(int[] verticies, SubdivisionWeight weight)
+ {
+
+ }
+
}
}
diff --git a/Assets/Algorithms/PathFinding/AStarPathfinding.cs b/Assets/Algorithms/PathFinding/AStarPathfinding.cs index 88d3e94..312ec41 100644 --- a/Assets/Algorithms/PathFinding/AStarPathfinding.cs +++ b/Assets/Algorithms/PathFinding/AStarPathfinding.cs @@ -1,18 +1,13 @@ -//using System.Collections; -//using System.Collections.Generic; -//using UnityEngine; - -//public class AStarPathfinding : MonoBehaviour -//{ -// // Start is called before the first frame update -// void Start() -// { - -// } - -// // Update is called once per frame -// void Update() -// { - -// } -//} +using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+
+namespace AlgorithmCollection.PathFinding
+{
+ public static class AStarPathfinding
+ {
+
+
+ }
+}
diff --git a/Assets/Algorithms/PathFinding/DijkstraPathfinding.cs b/Assets/Algorithms/PathFinding/DijkstraPathfinding.cs new file mode 100644 index 0000000..87f0074 --- /dev/null +++ b/Assets/Algorithms/PathFinding/DijkstraPathfinding.cs @@ -0,0 +1,13 @@ +using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+
+namespace AlgorithmCollection.PathFinding
+{
+ public static class DijkstraPathfinding
+ {
+
+
+ }
+}
diff --git a/Assets/Algorithms/PathFinding/DijkstraPathfinding.cs.meta b/Assets/Algorithms/PathFinding/DijkstraPathfinding.cs.meta new file mode 100644 index 0000000..cf1299a --- /dev/null +++ b/Assets/Algorithms/PathFinding/DijkstraPathfinding.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8acbcdf276956c145a32df50596952cb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Algorithms/Recursion/Recursion_DP.cs b/Assets/Algorithms/Recursion/Recursion_DP.cs index a0205ba..f672ebc 100644 --- a/Assets/Algorithms/Recursion/Recursion_DP.cs +++ b/Assets/Algorithms/Recursion/Recursion_DP.cs @@ -102,5 +102,7 @@ namespace AlgorithmCollection.Recursion return max;
}
+
+
}
}
\ No newline at end of file diff --git a/Assets/Algorithms/Recursion/Recursion_Greedy.cs b/Assets/Algorithms/Recursion/Recursion_Greedy.cs new file mode 100644 index 0000000..f332640 --- /dev/null +++ b/Assets/Algorithms/Recursion/Recursion_Greedy.cs @@ -0,0 +1,15 @@ +using System;
+using System.Collections;
+using System.Collections.Generic;
+using AlgorithmCollection;
+using UnityEngine;
+
+// 贪心算法
+namespace AlgorithmCollection.Recursion
+{
+
+ public static partial class RecursionHelper
+ {
+
+ }
+}
\ No newline at end of file diff --git a/Assets/Algorithms/Recursion/Recursion_Greedy.cs.meta b/Assets/Algorithms/Recursion/Recursion_Greedy.cs.meta new file mode 100644 index 0000000..3f00ca9 --- /dev/null +++ b/Assets/Algorithms/Recursion/Recursion_Greedy.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b56f042655312d44388ead1823593284 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Algorithms/Searching/SearchingHelper.cs b/Assets/Algorithms/Searching/SearchingHelper.cs index 191ff5e..d177957 100644 --- a/Assets/Algorithms/Searching/SearchingHelper.cs +++ b/Assets/Algorithms/Searching/SearchingHelper.cs @@ -34,7 +34,7 @@ namespace AlgorithmCollection.Searching public static int BinarySearch<T>(List<T> data, T value) where T : IComparable, IEquatable<T>
{
int index = -1;
- RecursionHelper.DNC(
+ RecursionHelper.DC(
() =>
{
DivisionDescriptor div = new DivisionDescriptor();
@@ -116,7 +116,7 @@ namespace AlgorithmCollection.Searching { bool suc = false; T v = default(T); - RecursionHelper.DNC( + RecursionHelper.DC( ()=> {
DivisionDescriptor div = new DivisionDescriptor();
|