- //冒泡排序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;
- }
- //该片段来自于http://www.codesnippet.cn/detail/0109201513611.html
来源: http://www.codesnippet.cn/detail/0109201513611.html