Ejemplo n.º 1
0
        public override int[] Sort(bool isDescending)
        {
            for (int j = 0; j < array.Length - 1; j++)
            {
                if (array[j + 1].CompareTo(array[j]) < 0)
                {
                    Swap(j, j + 1);

                    for (int i = j; i > 0; i--)
                    {
                        if (array[i].CompareTo(array[i - 1]) < 0)
                        {
                            Swap(i, i - 1);
                        }
                    }
                }
            }
            // checking if we need to invert array
            if (isDescending)
            {
                array = SorterUtils.ChangeDirection(array); // inverting array
            }

            return(array);
        }
Ejemplo n.º 2
0
        //Bubble sorting method
        public override int [] Sort(bool isDescending)
        {
            bool isSwapped;

            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 untill there was no swap

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

            return(array);
        }
Ejemplo n.º 3
0
        public override int[] Sort(bool isDescending)
        {
            Quicksort(array);

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

            return(array);
        }