Beispiel #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();
        }
        public static IExercise <T> GetExercise <T>(int option)
        {
            IExercise <T> exercise = null;

            switch (option)
            {
            case 5:
                exercise = new BubbleSortAlgorithm <T>();
                break;

            case 6:
                exercise = new MergeSortRecursive <T>();
                break;

            case 7:
                exercise = new MergeSortIterative <T>();
                break;

            case 8:
                exercise = new LinkedListStructure <T>();
                break;

            default:
                break;
            }

            return(exercise);
        }
Beispiel #3
0
        public void TestSortListOfString()
        {
            var sortingAlgorithm = new BubbleSortAlgorithm();

            var result = sortingAlgorithm.Sort <string>(_stringList, _cancellationToken, _progress);

            Assert.AreEqual("Four", result[0]);
            Assert.AreEqual("One", result[1]);
            Assert.AreEqual("Three", result[2]);
            Assert.AreEqual("Two", result[3]);
        }
Beispiel #4
0
        public void TestSortListOfChar()
        {
            var sortingAlgorithm = new BubbleSortAlgorithm();

            var result = sortingAlgorithm.Sort <char>(_charLists, _cancellationToken, _progress);

            Assert.AreEqual('a', result[0]);
            Assert.AreEqual('b', result[1]);
            Assert.AreEqual('b', result[2]);
            Assert.AreEqual('z', result[3]);
        }
Beispiel #5
0
        public MainWindow()
        {
            InitializeComponent();
            var selectedAlgorithm = new BubbleSortAlgorithm();

            algorithmsComboBox.Items.Add(selectedAlgorithm);
            algorithmsComboBox.Items.Add(new QuicksortAlgorithm());
            algorithmsComboBox.Items.Add(new InsertionSortAlgorithm());
            algorithmsComboBox.Items.Add(new SelectionSortAlgorithm());
            algorithmsComboBox.SelectedItem = selectedAlgorithm;
        }
Beispiel #6
0
        public void TestSortListOfInt()
        {
            var sortingAlgorithm = new BubbleSortAlgorithm();

            var result = sortingAlgorithm.Sort <int>(_intLists, _cancellationToken, _progress);

            Assert.AreEqual(-1, result[0]);
            Assert.AreEqual(0, result[1]);
            Assert.AreEqual(1, result[2]);
            Assert.AreEqual(5, result[3]);
            Assert.AreEqual(10, result[4]);
            Assert.AreEqual(10, result[5]);
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            ISortingAlgorithm bubbleSortAlgorithm = new BubbleSortAlgorithm();

            SubMain(bubbleSortAlgorithm);
            ISortingAlgorithm insertionSortAlgorithm = new InsertionSortAlgorithm();

            SubMain(insertionSortAlgorithm);
            ISortingAlgorithm selectionSortAlgorithm = new SelectionSortAlgorithm();

            SubMain(selectionSortAlgorithm);
            Console.ReadKey();
        }
Beispiel #8
0
        static void Main(string[] args)
        {
            int[] arr = { 34, 534, 45, 23, 346, 34, 5 };

            Sorter sorter = new Sorter(arr);

            ISortAlgorithm algo = new BubbleSortAlgorithm();

            sorter.setAlgorithm(algo);
            sorter.sort();

            algo = new MergeSortAlgorithm();
            sorter.setAlgorithm(algo);
            sorter.sort();
        }
        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);
            }
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            int[] arr = { 5, 346, 34, 634, 6, 346, 4 };

            Sorter sorter = new Sorter(arr);

            IComparator comparator = new AscComparator();

            ISortAlgorithm algo = new BubbleSortAlgorithm(comparator);

            sorter.setAlgorithm(algo);
            sorter.sort();

            algo = new MergeSortAlgorithm(comparator);
            sorter.setAlgorithm(algo);
            sorter.sort();
        }