public static void StringSort(ref string[] arrString, compareDel metodSort)
 {
     for (int i = 0; i < arrString.Length - 1; i++)
     {
         for (int j = i; j < arrString.Length; j++)
         {
             if (metodSort(arrString[i], arrString[j]))
             {
                 swap(ref arrString[i], ref arrString[j]);
             }
         }
     }
 }
示例#2
0
 private static void Sort(int[] strList, compareDel compare)
 {
     for (int i = 0; i < strList.Length; i++)
     {
         for (int j = i + 1; j < strList.Length; j++)
         {
             if (compare(strList[i], strList[j]))
             {
                 //將內部設為空目的為增加撰寫時可讀性
                 //讓 17行 可以將if (cur<las) 設為 true
                 //爾後可以直覺寫主程式,不用了解委派
             }
             else
             {
                 var temp = strList[i];
                 strList[i] = strList[j];
                 strList[j] = temp;
                 Console.WriteLine($"{string.Join(", ", strList)},交換了{strList[i]}");
             }
         }
     }
 }