From 8938c3447d88e31f77f20553ed185fc8e64c9ac8 Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 22 Jun 2021 14:58:53 +0800 Subject: +misc --- Assets/Test/05_Recursion/Test_Recursion.cs | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'Assets/Test/05_Recursion/Test_Recursion.cs') 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 data = new List { 'a', 'b', 'c' }; + //int count = 0; + //foreach (List 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 data = new List { 'a', 'b', 'c' }; + List data = new List { 'a', 'b', 'c' , 'd'}; int count = 0; - foreach (List p in RecursionHelper.Permutations(data)) + List> perms = new List>(); + RecursionHelper.Permutations(data, ref perms); + foreach (List 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 value2 = new List(){ 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 = ""; -- cgit v1.1-26-g67d0