Пример #1
0
        private void InsertionSort(dynamic array)
        {
            arr = (Array)array;

            dynamic watch = System.Diagnostics.Stopwatch.StartNew();

            for (int i = 0; i < arr.Count - 1; ++i)
            {
                for (int j = i + 1; j > 0; --j)
                {
                    if (arr[j - 1] > arr[j])
                    {
                        arr.Swap(j - 1, j);
                    }
                }
            }

            watch.Stop();
            long time = watch.ElapsedMilliseconds;

            StatusStripChange change = ChangeStatusStrip;

            statusStrip1.Invoke((Action)(() => change($"Insertion sorted. Time elapsed: { time.ToString()} ms")));

            PrintOn p = PrintOnArr;

            label1.Invoke(p);
        }
Пример #2
0
        private void SelectionSort(dynamic array)
        {
            arr = (Array)array;

            dynamic watch = System.Diagnostics.Stopwatch.StartNew();

            int min;

            for (int i = 0; i < arr.Count - 1; ++i)
            {
                min = i;
                for (int j = i + 1; j < arr.Count; ++j)
                {
                    if (arr[min] > arr[j])
                    {
                        min = j;
                    }
                }
                arr.Swap(i, min);
            }

            watch.Stop();
            long time = watch.ElapsedMilliseconds;

            StatusStripChange change = ChangeStatusStrip;

            statusStrip1.Invoke((Action)(() => change($"Selection sorted. Time elapsed: { time.ToString()} ms")));

            PrintOn p = PrintOnArr;

            label1.Invoke(p);
        }
Пример #3
0
        public void QuickSortFinalStep()
        {
            dynamic watch = System.Diagnostics.Stopwatch.StartNew();

            QuickSort(arr, 0, arr.Count - 1);

            watch.Stop();
            long time = watch.ElapsedMilliseconds;

            StatusStripChange change = ChangeStatusStrip;

            statusStrip1.Invoke((Action)(() => change($"Quick sorted. Time elapsed: { time.ToString()} ms")));

            PrintOn p = PrintOnArr;

            label1.Invoke(p);
        }
Пример #4
0
        private void MergeSortFinalStep()
        {
            dynamic watch = System.Diagnostics.Stopwatch.StartNew();

            arr = MergeSort(arr);

            watch.Stop();
            long time = watch.ElapsedMilliseconds;

            StatusStripChange change = ChangeStatusStrip;

            statusStrip1.Invoke((Action)(() => change($"Merge sorted. Time elapsed: { time.ToString()} ms")));

            PrintOn p = PrintOnArr;

            label1.Invoke(p);
        }