diff options
author | chai <chaifix@163.com> | 2021-06-21 22:59:39 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-06-21 22:59:39 +0800 |
commit | 5d81d8d8b4062def695c27fa02f67625871e8dce (patch) | |
tree | 1ab1a4b48b029e5f84d73cf0a6e7140782eb27e9 /Assets/Algorithms/Algorithms.cs | |
parent | cc475a8b16b0e9323623c6532e114dceeb64353a (diff) |
*misc
Diffstat (limited to 'Assets/Algorithms/Algorithms.cs')
-rw-r--r-- | Assets/Algorithms/Algorithms.cs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/Assets/Algorithms/Algorithms.cs b/Assets/Algorithms/Algorithms.cs index 31be4a8..f376ac6 100644 --- a/Assets/Algorithms/Algorithms.cs +++ b/Assets/Algorithms/Algorithms.cs @@ -1,4 +1,5 @@ -using System.Collections;
+using System;
+using System.Collections;
using System.Collections.Generic;
using UnityEngine;
@@ -21,6 +22,13 @@ namespace AlgorithmCollection data[i2] = temp;
}
+ public static void Swap<T>(ref T[] data, int i1, int i2)
+ {
+ T temp = data[i1];
+ data[i1] = data[i2];
+ data[i2] = temp;
+ }
+
// 阶乘
public static int Factorial(int n)
{
@@ -29,6 +37,11 @@ namespace AlgorithmCollection return n * Factorial(n - 1);
}
+ public static T Min<T>(T v1, T v2) where T : IComparable
+ {
+ return v1.CompareTo(v2) < 0 ? v1 : v2;
+ }
+
}
}
\ No newline at end of file |