예제 #1
0
 /// <summary>
 /// Subscribe method, once sorting will be completed
 /// </summary>
 /// <param name="args">event args</param>
 public void OnArrayWasSorted(ArrayWasSortedEventArgs args)
 {
     lock (locker)
     {
         Console.WriteLine("\n\nArray was sorted with:<{0}>. \nWith Elapsed time:<{1}>: \n______", args.SorterName, args.stopWatch.Elapsed);
         SortUtil.Print2DArrayToConsole(SortUtil.Convert1DArraTo2D(args.Array1D, current2DArray.GetLength(0), current2DArray.GetLength(1)));
         counterForOutputs++;
     }
 }
예제 #2
0
        /// <summary>
        /// This method contain the logic for sorting singl and multiple sorters.
        /// </summary>
        /// <param name="isSortWithAllSortersSimultaneously">true - in case of need to sort with all sorters simultaneously, false - in vice versa</param>
        private void MenuDialog_SortingMenuHandler(bool isSortWithAllSortersSimultaneously)
        {
            PrefixSortMenuHandler(isSortWithAllSortersSimultaneously);

            CheckForAscDescSelection();

            current1DArray = SortUtil.Convert2DArrayTo1D(current2DArray);

            //run sorting itself. In multithreads, or in single.
            if (isSortWithAllSortersSimultaneously)
            {
                foreach (ISorter sorter in sorterList)
                {
                    Stopwatch stopWatch = new Stopwatch();

                    //init thread
                    Thread sorterThread = new Thread(
                        () =>
                    {
                        stopWatch.Start();
                        sorter.Sort((int[])current1DArray.Clone(), isAscSorting);

                        stopWatch.Stop();
                    });
                    sorterThread.Start();
                }
                //wait untill all results will be printed to screen
                while (counterForOutputs < sorterList.Count)
                {
                }
            }
            else
            {
                current1DArray = sorterList.ElementAt(userSelectionMainMenu - menuNumberConst).Sort(current1DArray, isAscSorting);
                current2DArray = SortUtil.Convert1DArraTo2D(current1DArray, current2DArray.GetLength(0), current2DArray.GetLength(1));
            }
            Console.WriteLine("Array was sorted with <<{0}>>. \nPlease press anykey get back to Main menu....", sortingModePrefix);
            Console.ReadKey();
        }