Example #1
0
    // 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);
    }
Example #2
0
    // 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);
    }
Example #3
0
    // 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);
    }
Example #4
0
    // 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);
    }
Example #5
0
    // 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;
    }
Example #6
0
    // Use this for initialization
    void Start()
    {
        //测试极小堆
        print("------------------测试极小堆------------------");
        int capicity = 100;
        int n        = 10;

        int[]         arr        = AlgorithmsHelp.generateRandomArray(n, 1, 20);
        MinHeap <int> minHeap    = new MinHeap <int> (100);
        MinHeap <int> minarrHeap = new MinHeap <int> (arr, 100);

        for (int i = 0; i != n; i++)
        {
            minHeap.Insert(arr[i]);
        }

        minHeap.print();

        minarrHeap.print();
        string str = "";

        while (minHeap.Size() > 0)
        {
            str += minHeap.ExtraMinItem() + " ";
        }
        Debug.Log(str);

        testChangeInNormalHeap(minarrHeap);
        print("------------------------------------------");
        print("------------------测试极小索引堆------------------");

        //测试极小索引堆
        arr = AlgorithmsHelp.generateRandomArray(n, 1, 20);
        IndexMinHeap <int> minIndexHeap    = new IndexMinHeap <int>(100);
        IndexMinHeap <int> minarrIndexHeap = new IndexMinHeap <int>(arr, 100);

        for (int i = 0; i != n; i++)
        {
            minIndexHeap.Insert(arr[i]);
        }
        minIndexHeap.print();
        minarrIndexHeap.print();

        str = "";
        while (minIndexHeap.Size() > 0)
        {
            str += minIndexHeap.ExtraMinItem() + " ";
        }
        print("从小到大排序 " + str);
        testChangeInIndexHeap(minarrIndexHeap);

//		测试极大堆
//		int capicity = 100;
//		int n = 10;
//		Heap<int> maxHeap = new Heap<int> (100);
//		int[] arr = AlgorithmsHelp.generateRandomArray (n,1,20);
//		for (int i = 0; i != n; i++) {
//			maxHeap.Insert (arr[i]);
//		}
//		maxHeap.printData ();
//
//		string str = "";
//		for (int i = 0; i != n; i++) {
//			str +=maxHeap.ExtractBigItem()+" ";
//		}
//		print ("data[] : " +str);
    }