From 5d81d8d8b4062def695c27fa02f67625871e8dce Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 21 Jun 2021 22:59:39 +0800 Subject: *misc --- Assets/Algorithms/Algorithms.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'Assets/Algorithms/Algorithms.cs') 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(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 v1, T v2) where T : IComparable + { + return v1.CompareTo(v2) < 0 ? v1 : v2; + } + } } \ No newline at end of file -- cgit v1.1-26-g67d0