| 步骤 7. 创建函数
最后一步就是创建一个函数来在字符串数组中运行 QuickSort.我们将此函数放到应用程序类 QuickSortApp 之中。 修改源代码更改 C# 源文件 (class1.cs),如下面以斜体突出显示的 代码所示。其他的差异(如类名)可忽略不计。 // Import namespaces !--判断阅读权限-->!--判断是否已经扣点-->using System; using System.Collections; using System.IO; // Declare namespace namespace MsdnAA { // Declare application class class QuickSortApp { // Application initialization static void Main (string[] szArgs) { ... ... ... // Pass to QuickSort function QuickSort (szContents, 0, szContents.Count - 1); ... ... ... } // QuickSort implementation static void QuickSort (ArrayList szArray, int nLower, int nUpper) { // Check for non-base case if (nLower < nUpper) { // Split and sort partitions int nSplit = Partition (szArray, nLower, nUpper); QuickSort (szArray, nLower, nSplit - 1); QuickSort (szArray, nSplit + 1, nUpper); } } // QuickSort partition implementation static int Partition (ArrayList szArray, int nLower, int nUpper) |
