summaryrefslogtreecommitdiff
path: root/Assets/Test/05_Recursion
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/Test/05_Recursion
parent5d81d8d8b4062def695c27fa02f67625871e8dce (diff)
+misc
Diffstat (limited to 'Assets/Test/05_Recursion')
-rw-r--r--Assets/Test/05_Recursion/Test_Recursion.cs30
1 files changed, 25 insertions, 5 deletions
diff --git a/Assets/Test/05_Recursion/Test_Recursion.cs b/Assets/Test/05_Recursion/Test_Recursion.cs
index ac9de5e..7529270 100644
--- a/Assets/Test/05_Recursion/Test_Recursion.cs
+++ b/Assets/Test/05_Recursion/Test_Recursion.cs
@@ -10,21 +10,35 @@ public class Test_Recursion : MonoBehaviour
{
void Start()
{
- //TestPermutations();
+ TestPermutations();
//TestHanoi();
//TestBinarySearch();
//TestMergeSort();
//TestQuickSort();
- TestBubbleSort();
+ //TestBubbleSort();
}
void TestPermutations()
{
// 全排列
+ //Debug.Log("全排列");
+ //List<char> data = new List<char> { 'a', 'b', 'c' };
+ //int count = 0;
+ //foreach (List<char> p in RecursionHelper.Permutations(data))
+ //{
+ // count++;
+ // string content = "";
+ // p.ForEach((char c) => content += c + " ");
+ // Debug.Log(content);
+ //}
+ //Debug.Assert(count == Algorithms.Factorial(data.Count));
+
Debug.Log("全排列");
- List<char> data = new List<char> { 'a', 'b', 'c' };
+ List<char> data = new List<char> { 'a', 'b', 'c' , 'd'};
int count = 0;
- foreach (List<char> p in RecursionHelper.Permutations(data))
+ List<List<char>> perms = new List<List<char>>();
+ RecursionHelper.Permutations(data, ref perms);
+ foreach (List<char> p in perms)
{
count++;
string content = "";
@@ -54,13 +68,18 @@ public class Test_Recursion : MonoBehaviour
void TestBinarySearch()
{
Debug.Log("二分搜索");
- int[] value = {1,2,5,6,7,8 }; //升序数组
+ int[] value = { 1, 2, 3, 6, 7, 8 }; //升序数组
int index = SearchingHelper.BinarySearch(value, 6);
Debug.Log(index);
+
+ List<int> value2 = new List<int>(){ 1, 2, 3, 6, 7, 8 }; //升序数组
+ index = SearchingHelper.BinarySearch(value2, 3);
+ Debug.Log(index);
}
void TestMergeSort()
{
+ // 局部有序->整体有序
int[] value = { 9, 7, 2, 3, 4, 6, 1 };
SortingHelper.MergeSort(value, true);
string content = "";
@@ -81,6 +100,7 @@ public class Test_Recursion : MonoBehaviour
void TestQuickSort()
{
+ // 整体有序->局部有序
int[] value = { 9, 7, 2, 3, 4, 6, 1 };
SortingHelper.QuickSort(value, true);
string content = "";