summaryrefslogtreecommitdiff
path: root/Assets/Algorithms/Algorithms.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Algorithms/Algorithms.cs')
-rw-r--r--Assets/Algorithms/Algorithms.cs15
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