C#
/// <summary>
/// 交换a和b的值
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="a"></param>
/// <param name="b"></param>
public static void Swap<T>(ref T a, ref T b){
T t = a;
a = b;
b = t;
}
C++
template<typename T> void swap(T &a,T &b) { T temp(a); a = b; b = temp; }
java
public static <T> void swap(T[] arr,int n1,int n2){
T tmp = arr[n1];
arr[n1] = arr[n2];
arr[n2] = tmp;
}
public static void swap(int[] arr,int n1,int n2){
int tmp = arr[n1];
arr[n1] = arr[n2];
arr[n2] = tmp;
}
public static void swap(double[] arr,int n1,int n2){
double tmp = arr[n1];
arr[n1] = arr[n2];
arr[n2] = tmp;
}
................
................. 还没完