示例#1
0
        static void Main(string[] args)
        {
            int[] arr = { 10, 80, 30, 90, 40, 50, 70 };

            BubbleSortAlgorithm bubbleSort = new BubbleSortAlgorithm();

            InsertSortAlgorithm insertSort = new InsertSortAlgorithm();

            ShellSortAlgorithm shellSort = new ShellSortAlgorithm();

            HeapSortAlgorithm heapSort = new HeapSortAlgorithm();

            SelectionSortAlgorithm selectSort = new SelectionSortAlgorithm();

            MergeSortAlgorithm mergeSort = new MergeSortAlgorithm();

            QuickSortAlgorithm quickSort = new QuickSortAlgorithm();


            arr = quickSort.Sort(arr);

            for (int i = 0; i < arr.Length; i++)
            {
                Console.Write(arr[i]);
                Console.Write(' ');
            }
            Console.WriteLine();

            Console.ReadLine();
        }
示例#2
0
        private void Sort(int[] intTempArray, SortType sortType, CancellationToken cToken, HSBColor[] floatSortArray, bool hsb, int delay)
        {
            ISortingAlgorithm sortingAlgorithm = null;

            switch (sortType)
            {
            case SortType.QuickSort:
                sortingAlgorithm = new QuickSortAlgorithm();
                break;

            case SortType.BubbleSort:
                sortingAlgorithm = new BubbleSortAlgorithm();
                break;

            case SortType.HeapSort:
                sortingAlgorithm = new HeapSortAlgorithm();
                break;

            case SortType.SelectionSort:
                sortingAlgorithm = new SelectionSortAlgorithm();
                break;

            case SortType.MergeSort:
                sortingAlgorithm = new MergeSortAlgorithm();
                break;
                break;

            case SortType.ParalellMergeSort:
                sortingAlgorithm = new ParalellMergeSortAlgorithm();
                break;
            }

            sortingAlgorithm.Token = cToken;


            sortingAlgorithm.Delay = delay;

            if (hsb)
            {
                sortingAlgorithm.Sort(intTempArray, floatSortArray);
            }
            else
            {
                sortingAlgorithm.Sort(intTempArray);
            }
        }
示例#3
0
        private static int[] Sorting()
        {
            int[] arr = new int[] { 8, 3, 2, 7, 9, 1, 4, 1 };
            Console.WriteLine("\n");
            Console.WriteLine("Before HeapSort:");
            foreach (int i in arr)
            {
                Console.Write(i + ",");
            }
            Console.ReadLine();
            HeapSortAlgorithm.HeapSort(arr);

            Console.WriteLine("\n");
            Console.WriteLine("After HeapSort:");
            foreach (int i in arr)
            {
                Console.Write(i + ",");
            }
            Console.WriteLine("\n");
            Console.ReadLine();

            arr = new int[] { 4, 88, 23, 65, 2, 89, 7, 3, 1, 90, 4 };

            Console.WriteLine("\n");
            Console.WriteLine("Before MergeSort:");
            foreach (int i in arr)
            {
                Console.Write(i + ",");
            }
            Console.ReadLine();
            MergeSortAlgorithm.MergeSort(arr, 0, arr.Length - 1);

            Console.WriteLine("\n");
            Console.WriteLine("After MergeSort:");
            foreach (int i in arr)
            {
                Console.Write(i + ",");
            }
            Console.WriteLine("\n");
            Console.ReadLine();

            arr = new int[] { 8, 3, 2, 7, 9, 1, 4, 1 };

            Console.WriteLine("\n");
            Console.WriteLine("Before QuickSort:");
            foreach (int i in arr)
            {
                Console.Write(i + ",");
            }
            Console.ReadLine();
            QuickSortAlgorithm.QuickSort(arr, 0, arr.Length - 1);

            Console.WriteLine("\n");
            Console.WriteLine("After QuickSort:");
            foreach (int i in arr)
            {
                Console.Write(i + ",");
            }
            Console.WriteLine("\n");
            Console.ReadLine();
            return(arr);
        }