标签:
static void quick_sort(int[] s ,int l, int r) { int i = l, j = r, t, x = s[l]; while (j > i) { while (s[j] >= x && i <j) { j--; } while (s[i] <= x && i<j) { i++; } if (j > i) { t=s[i]; s[i] = s[j]; s[j] = t; } } s[l] = s[i]; s[i] = x; //Console.WriteLine(string.Join(",",s)); if(i>l) quick_sort(s, l, i - 1); if(j<r) quick_sort(s, i + 1, r); Console.WriteLine(string.Join(",",s)); }
调用方式
int[] array = { 6, 1, 2, 7, 9, 3, 4, 5, 10, 8 }; int index=4; int t = array[index]; quick_sort(array, 0, array.Length-1);
标签:
原文地址:http://www.cnblogs.com/heye/p/4467632.html