diff options
| author | chai <chaifix@163.com> | 2021-06-21 15:53:42 +0800 | 
|---|---|---|
| committer | chai <chaifix@163.com> | 2021-06-21 15:53:42 +0800 | 
| commit | cc475a8b16b0e9323623c6532e114dceeb64353a (patch) | |
| tree | 0d57c6afd973ed03a66e614038d9c9ef1acb790b /Assets/Algorithms/Algorithms.cs | |
| parent | 2283e4eda5ed0ef8760bef495b6ca60297b36404 (diff) | |
+recursions
Diffstat (limited to 'Assets/Algorithms/Algorithms.cs')
| -rw-r--r-- | Assets/Algorithms/Algorithms.cs | 34 | 
1 files changed, 34 insertions, 0 deletions
| diff --git a/Assets/Algorithms/Algorithms.cs b/Assets/Algorithms/Algorithms.cs new file mode 100644 index 0000000..31be4a8 --- /dev/null +++ b/Assets/Algorithms/Algorithms.cs @@ -0,0 +1,34 @@ +using System.Collections;
 +using System.Collections.Generic;
 +using UnityEngine;
 +
 +namespace AlgorithmCollection
 +{
 +
 +    public static partial class Algorithms
 +    {
 +        public static void Swap<T>(ref T v1, ref T v2)
 +        {
 +            T temp = v1;
 +            v1 = v2;
 +            v2 = temp;
 +        }
 +
 +        public static void Swap<T>(ref List<T> data, int i1, int i2)
 +        {
 +            T temp = data[i1];
 +            data[i1] = data[i2];
 +            data[i2] = temp;
 +        }
 +
 +        // 阶乘
 +        public static int Factorial(int n)
 +        {
 +            if (n == 1)
 +                return 1;
 +            return n * Factorial(n - 1);
 +        }
 +
 +    }
 +
 +}
\ No newline at end of file | 
