summaryrefslogtreecommitdiff
path: root/Assets/Algorithms/Recursion.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-06-22 14:58:53 +0800
committerchai <chaifix@163.com>2021-06-22 14:58:53 +0800
commit8938c3447d88e31f77f20553ed185fc8e64c9ac8 (patch)
tree0b13d53b203323891826a600febfe4e90c991a36 /Assets/Algorithms/Recursion.cs
parent5d81d8d8b4062def695c27fa02f67625871e8dce (diff)
+misc
Diffstat (limited to 'Assets/Algorithms/Recursion.cs')
-rw-r--r--Assets/Algorithms/Recursion.cs72
1 files changed, 0 insertions, 72 deletions
diff --git a/Assets/Algorithms/Recursion.cs b/Assets/Algorithms/Recursion.cs
deleted file mode 100644
index 5a02035..0000000
--- a/Assets/Algorithms/Recursion.cs
+++ /dev/null
@@ -1,72 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using AlgorithmCollection;
-
-// 递归与分治算法
-
-namespace AlgorithmCollection.Recursion
-{
-
- public static class RecursionHelper
- {
-
- #region 全排列,返回数据的所有组合
- public static void Permutations<T>(List<T> data, ref List<List<T>> perms)
- {
- if (perms == null)
- perms = new List<List<T>>();
- foreach (List<T> perm in perms)
- {
- List<T> p = new List<T>(perm);
- perms.Add(p);
- }
- }
-
- // 生成器形式,每次返回一个组合
- public static IEnumerable Permutations<T>(List<T> data)
- {
- foreach (var perm in _Permutations(data, 0, data.Count - 1))
- {
- yield return perm;
- }
- }
-
- // 计算start~end范围内的全排列
- private static IEnumerable _Permutations<T>(List<T> data, int start, int end, List<T> perm = null)
- {
- if (perm == null)
- perm = new List<T>(data.Count);
- if (start == end)
- {
- perm.Add(data[start]);
- yield return perm;
- perm.RemoveAt(perm.Count - 1);
- }
- else
- {
- for (int i = start; i <= end; ++i)
- {
- perm.Add(data[i]);
- Algorithms.Swap(ref data, start, i);
- IEnumerator itor = _Permutations(data, start + 1, end, perm).GetEnumerator();
- while (itor.MoveNext())
- yield return itor.Current;
- Algorithms.Swap(ref data, start, i);
- perm.RemoveAt(perm.Count - 1);
- }
- }
- }
- #endregion
-
- #region 分治
-
- public static void DivideAndConquer()
- {
-
- }
-
- #endregion
-
- }
-} \ No newline at end of file