Exemplo n.º 1
0
        public event SortingFinishedEventHandler SortingFinished; // event which will be rised after sorting will finish

        public override void Sort(bool isDescending, int[,] arrayforSorting)
        {
            // Getting i and j values from arrived 2D array for future back conversion from 1D to 2D array
            amountOfRaws    = arrayforSorting.GetLength(0);
            amountOfColumns = arrayforSorting.GetLength(1);

            array = SorterUtils.ConvertArrayTo1D(arrayforSorting); //converting 2d array to 1d

            sortingStopwatch.Start();                              //starting stopwatch
            selectSort(array);                                     // Sorting
            sortingStopwatch.Stop();                               //stopping stopwatch

            // checking if we need to invert array
            if (isDescending)
            {
                array = SorterUtils.ChangeDirection(array); // inverting array
            }

            TimeSpan sortingTime = sortingStopwatch.Elapsed;

            OnSortingFinished(array, amountOfRaws, amountOfColumns, sortingTime); //rising event
        }
Exemplo n.º 2
0
        public event SortingFinishedEventHandler SortingFinished; // event which will be rised after sorting will finish

        public override void Sort(bool isDescending, int[,] arrayforSorting)
        {
            bool isSwapped;

            // Getting i and j values from arrived 2D array for future back conversion from 1D to 2D array
            amountOfRaws    = arrayforSorting.GetLength(0);
            amountOfColumns = arrayforSorting.GetLength(1);

            array = SorterUtils.ConvertArrayTo1D(arrayforSorting); //converting 2d array to 1d

            sortingStopwatch.Start();                              //starting stopwatch

            //Sorting...
            do
            {
                isSwapped = false;

                for (int j = 0; j < array.Length - 1; j++)
                {
                    if (array[j].CompareTo(array[j + 1]) > 0) //comparing values and if next value less than previous  - swapping values
                    {
                        Swap(j, j + 1);
                        isSwapped = true;
                    }
                }
            } while (isSwapped);     // repit cycle until there was no swap

            sortingStopwatch.Stop(); //stopping stopwatch

            // checking if we need to invert array
            if (isDescending)
            {
                array = SorterUtils.ChangeDirection(array); // inverting array
            }

            sortingTime = sortingStopwatch.Elapsed;

            OnSortingFinished(array, amountOfRaws, amountOfColumns, sortingTime); //rising event
        }
Exemplo n.º 3
0
 public Sorter(int[,] arrayforSorting)
 {
     array = SorterUtils.ConvertArrayTo1D(arrayforSorting); //converting 2d array to 1d in constuctor
 }