// Use this for initialization void Start() { int n = 1900; int[] arr = AlgorithmsHelp.generateRandomArray(n, 1, n); int[] arrCp = AlgorithmsHelp.CopyIntArray(arr, n); int[] arrCp2 = AlgorithmsHelp.CopyIntArray(arr, n); // AlgorithmsHelp.testSort ("MerSort", MergesSort.MergeSort, arr, n); // AlgorithmsHelp.testSort ("QuickSort1", QuickSort, arrCp, n); // AlgorithmsHelp.testSort ("QuickSort2", QuickSort2, arrCp2, n); // AlgorithmsHelp.testSort ("QuickSort3", QuickSort3, arrCp2, n); // // arr = AlgorithmsHelp.generateNearlyOrderArray(n,5); // arrCp = AlgorithmsHelp.CopyIntArray(arr,n); // arrCp2 = AlgorithmsHelp.CopyIntArray (arr,n); // AlgorithmsHelp.testSort ("MerSort", MergesSort.MergeSort, arr, n); // AlgorithmsHelp.testSort ("QuickSort1", QuickSort, arrCp, n); // AlgorithmsHelp.testSort ("QuickSort2", QuickSort2, arrCp2, n); // AlgorithmsHelp.testSort ("QuickSort3", QuickSort3, arrCp2, n); arr = AlgorithmsHelp.generateRandomArray(n, 1, 10); arrCp = AlgorithmsHelp.CopyIntArray(arr, n); arrCp2 = AlgorithmsHelp.CopyIntArray(arr, n); AlgorithmsHelp.testSort("MerSort", MergesSort.MergeSort, arr, n); AlgorithmsHelp.testSort("QuickSort1", QuickSort, arrCp, n); AlgorithmsHelp.testSort("QuickSort2", QuickSort2, arrCp2, n); AlgorithmsHelp.testSort("QuickSort3", QuickSort3, arrCp2, n); // // arr = AlgorithmsHelp.generateRandomArray(n,1,5); // AlgorithmsHelp.testSort ("QuickSort", QuickSort, arr, n); // int[] arr = AlgorithmsHelp.generateNearlyOrderArray(n,5); // AlgorithmsHelp.testSort ("QuickSort", QuickSort, arr, n); }
// Use this for initialization void Start() { int n = 1000; int[] arr = AlgorithmsHelp.generateRandomArray(n, 1, 3); int[] arrcopy = AlgorithmsHelp.CopyIntArray(arr, n); AlgorithmsHelp.testSort("BubbleSort", BubblableSort, arr, n); AlgorithmsHelp.printData(arr); AlgorithmsHelp.testSort("BubbleSort1", BubblableSort1, arrcopy, n); AlgorithmsHelp.printData(arrcopy); }
// Use this for initialization void Start() { int n = 30000000; int[] a = AlgorithmsHelp.generateRandomArray(n, 1, 10 * n); int[] sameA = AlgorithmsHelp.CopyIntArray(a, n); int[] same2A = AlgorithmsHelp.CopyIntArray(a, n); // AlgorithmsHelp.printData (a); AlgorithmsHelp.testSort("Merge Sort", MergeSort, a, n); AlgorithmsHelp.testSort("Merge Sort1", MergeSort1, a, n); AlgorithmsHelp.testSort("Insert Sort1", InsertSort.InsertionSort1, a, n); // AlgorithmsHelp.printData (a); }
// Use this for initialization void Start() { int n = 1000000; int[] arr = AlgorithmsHelp.generateRandomArray(n, 1, n); int[] arrCopy1 = AlgorithmsHelp.CopyIntArray(arr, n); int[] arrCopy2 = AlgorithmsHelp.CopyIntArray(arr, n); int[] arrCopy3 = AlgorithmsHelp.CopyIntArray(arr, n); int[] arrCopy4 = AlgorithmsHelp.CopyIntArray(arr, n); AlgorithmsHelp.testSort("Merge Sort", MergesSort.MergeSort, arr, n); AlgorithmsHelp.testSort("Quick Sort 3 ways", QuickSorts.QuickSort3, arrCopy1, n); AlgorithmsHelp.testSort("Heap Sort", HeapSort, arrCopy2, n); AlgorithmsHelp.testSort("Heap Sort2", HeapSort2, arrCopy3, n); AlgorithmsHelp.testSort("Heap Sort3", HeapSort3, arrCopy4, n); // // // arr = AlgorithmsHelp.generateRandomArray (n,1,20); // arrCopy1 = AlgorithmsHelp.CopyIntArray (arr,n); // arrCopy2 = AlgorithmsHelp.CopyIntArray (arr, n); // arrCopy3 = AlgorithmsHelp.CopyIntArray (arr, n); // // // AlgorithmsHelp.testSort ("Merge Sort", MergesSort.MergeSort,arr,n); // AlgorithmsHelp.testSort ("Quick Sort 3 ways",QuickSorts.QuickSort3,arrCopy1,n); // AlgorithmsHelp.testSort ("Heap Sort", HeapSort, arrCopy2, n); // AlgorithmsHelp.testSort ("Heap Sort2", HeapSort2, arrCopy3, n); // // // arr = AlgorithmsHelp.generateNearlyOrderArray (n,20); // arrCopy1 = AlgorithmsHelp.CopyIntArray (arr,n); // arrCopy2 = AlgorithmsHelp.CopyIntArray (arr, n); // arrCopy3 = AlgorithmsHelp.CopyIntArray (arr, n); // // // AlgorithmsHelp.testSort ("Merge Sort", MergesSort.MergeSort,arr,n); // AlgorithmsHelp.testSort ("Quick Sort 3 ways",QuickSorts.QuickSort3,arrCopy1,n); // AlgorithmsHelp.testSort ("Heap Sort", HeapSort, arrCopy2, n); // AlgorithmsHelp.testSort ("Heap Sort2", HeapSort2, arrCopy3, n); }
// Use this for initialization void Start() { // int n = 1000; // //实验1 // int[] arr = AlgorithmsHelp.generateRandomArray (n, 1, n); // int[] sameArr = AlgorithmsHelp.CopyIntArray (arr,n); // AlgorithmsHelp.testSort ("InsertionSort1", InsertionSort1, sameArr, n); // AlgorithmsHelp.printData (sameArr); //// AlgorithmsHelp.testSort ("SelectionSort", SelectSort.SelectionSort,arr,n); //// AlgorithmsHelp.printData (sameArr); // AlgorithmsHelp.testSort ("InsertionSort", InsertionSort, arr, n); // AlgorithmsHelp.printData (arr); //实验2 比较有序数组的,选择排序的超快性 int n = 10000; int[] arr = AlgorithmsHelp.generateNearlyOrderArray(n, 10); int[] sameArr = AlgorithmsHelp.CopyIntArray(arr, n); AlgorithmsHelp.testSort("InsertionSort1", InsertionSort1, arr, n); AlgorithmsHelp.printData(arr); AlgorithmsHelp.testSort("SelectionSort", SelectSort.SelectionSort, sameArr, n); AlgorithmsHelp.printData(sameArr); }
// Use this for initialization void Start() { int[] a = { 3, 9, 8, 7, 6, 5, 4, 3, 2, 1 }; string s = ""; foreach (int num in a) { s += num + " "; } print(s + " "); s = ""; SelectionSort(a, 10); foreach (float num in a) { s += num + " "; } print(s + " "); s = ""; float[] b = { 4.4f, 3.3f, 2.2f, 1.1f }; foreach (var num in b) { s += num + " "; } print(s + " "); s = ""; SelectionSort(b, 4); foreach (var num in b) { s += num + " "; } print(s + " "); // 测试模板函数,传入字符串数组 string[] c = { "D", "C", "B", "A" }; s = ""; foreach (var num in c) { s += num + " "; } print(s + " "); s = ""; SelectionSort(c, 4); foreach (var num in c) { s += num + " "; } print(s + " "); Student[] d = { new Student("D", 90), new Student("C", 100), new Student("B", 95), new Student("A", 95) }; s = ""; foreach (var num in d) { print(num); } SelectionSort(d, 4); foreach (var num in d) { print(num); } int n = 10000; // a = null; // a = AlgorithmsHelp.generateRandomArray (n,1,n); // AlgorithmsHelp.printData (a); // SelectionSort(a,n); // AlgorithmsHelp.printData (a); // a = null; a = AlgorithmsHelp.generateRandomArray(n, 1, n); AlgorithmsHelp.printData(a); AlgorithmsHelp.testSort("SelectionSort", SelectionSort, a, n); AlgorithmsHelp.printData(a); int i = 3; float f = i; }