冒泡排序1: public void RisePot(ref int [] array) { int a = array.Length; for (int i = 0; i < a-1; i++) { for (int j = a - 1; j > i; j--) { if (array[i] > array[j]) { int temp = array[i]; array[i] = array[j]; array[j] = temp; } } } } 冒泡排序2: public void RisePot(ref int [] array) { int a = array.Length; for (int i = 0; i < a-1; i++) { for (int j = i+1; j <a; j++) { if (array[i] > array[j]) { int temp = array[i]; array[i] = array[j]; array[j] = temp; } } } } 快速排序: public void QuickSort(ref int [] arr,int low ,int high) { if (low < high) { int mid = GetMid(arr, low, high); QuickSort(ref arr, low, mid - 1); QuickSort(ref arr, mid + 1, high); } } public int GetMid(int[] array, int low, int high) { int temp = array[low]; while (low < high) { while (low < high && array[high] >= temp) { high--; } if (low < high) { array[low] = array[high]; low++; } while (low < high && array[low] <= temp) { low++; } if (low < high) { array[high] = array[low]; high--; } } array[low] = temp; return low; } 不使用第三变量交换两个整数的值 static void Main(string[] args) { int a = 1234, b = 6666; Swap(ref a, ref b); Console.WriteLine("{0},{1}",a,b); Console.Read(); } static void Swap(ref int a, ref int b) { a = b - a; b = b - a; a = a + b; }