using System; public class test { static int N = 110; static int n; private static void QuickSort(int [] a, int st, int en) { int pivot = a[(st + en)/2]; int i = st, j = en; while(i < j) { while(i < j && a[i] < pivot) i++; while(i < j && a[j] > pivot) j--; if(i <= j) { int t = a[i]; a[i] = a[j]; a[j] = t; i++; j--; } } if(i < en) QuickSort(a, i, en); if(j > st) QuickSort(a, st, j); } public static void Main() { int i, j, k; int[] a = new int[N]; n = Convert.ToInt32(Console.ReadLine()); Random randomizer = new Random(); for(i = 1; i <= n; i++) a[i] = randomizer.Next(0, 100); QuickSort(a, 1, n); for(int t = 1; t <= n; t++) Console.Write("{0,2}, ", a[t]); } }
QuickSort(C#) -- My First C# Program
最新推荐文章于 2024-09-02 07:15:00 发布