예제 #1
0
        //Bubble sorting method
        public override int[] Sort(bool isdescending)
        {
            bool isSwapped;
            bool isDescending = (bool)isdescending;

            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);
        }
예제 #2
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);
        }
예제 #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);
        }
예제 #4
0
 private void initSorterMenu()
 {
     m_SorterUtils = new SorterUtils();
     comboBoxCitiesSorter.Items.Add(new SorterItem {
         Text = "Highest First", CommandDelegate = m_SorterUtils.HighestFirst
     });
     comboBoxCitiesSorter.Items.Add(new SorterItem {
         Text = "Lowest First", CommandDelegate = m_SorterUtils.LowestFirst
     });
     comboBoxCitiesSorter.Items.Add(new SorterItem {
         Text = "News Sort Option", CommandDelegate = () => m_SorterUtils.Sorter = new Sorter((num1, num2) => num1 > num2)
     });
 }