コード例 #1
0
    public void TestManyElements()
    {
        var input = new[] { 1, 0, -1, 0, 1, -1 };

        sortingAlgorithm.Sort(input);

        Assert.AreEqual(new[] { -1, -1, 0, 0, 1, 1 }, input);
    }
コード例 #2
0
        private static void TestAsc(IList <int> enumerable, ISortable sortClass)
        {
            var sortedArray  = enumerable.OrderBy(x => x).ToArray();
            var arrayToCheck = sortClass.Sort(enumerable).ToArray();

            CollectionAssert.AreEqual(sortedArray, arrayToCheck);
        }
コード例 #3
0
 private static T[] Sort <T>(
     this T[] items, ISortable sortableStrategy) where T : IComparable <T>
 {
     T[] copy = items.CopyArray();
     StopWatch.Start();
     sortableStrategy.Sort(copy);
     StopWatch.Stop();
     return(copy);
 }
コード例 #4
0
        public virtual void SetModel(IListModel <T> value, double vpos)
        {
            if (model == value)
            {
                return;
            }

            if (model != null)
            {
                model.Cleared  -= OnModelClearedHandler;
                model.Reloaded -= OnModelReloadedHandler;
            }

            model = value;

            if (model != null)
            {
                model.Cleared            += OnModelClearedHandler;
                model.Reloaded           += OnModelReloadedHandler;
                selection_proxy.Selection = model.Selection;
                IsEverReorderable         = model.CanReorder;
            }

            if (ViewLayout != null)
            {
                ViewLayout.Model = Model;
            }

            ISortable sortable = model as ISortable;

            if (sortable != null && ColumnController != null)
            {
                ISortableColumn sort_column = ColumnController.SortColumn ?? ColumnController.DefaultSortColumn;
                if (sort_column != null)
                {
                    if (sortable.Sort(sort_column))
                    {
                        model.Reload();
                    }
                    RecalculateColumnSizes();
                    RegenerateColumnCache();
                    InvalidateHeader();
                    IsReorderable = sortable.SortColumn == null || sortable.SortColumn.SortType == SortType.None;
                }
            }

            RefreshViewForModel(vpos);

            var handler = ModelChanged;

            if (handler != null)
            {
                handler(this, EventArgs.Empty);
            }
        }
コード例 #5
0
        private void sortBttn_Click(object sender, EventArgs e)
        {
            bool goodInput = true;
            var  l         = ParseInputTextForCSV(ref goodInput);

            Debug.Assert(goodInput);
            ToBeSorted = l.ToArray();

            sortingAlgorithm.Sort(ToBeSorted);
            RewriteInputTxt(ToBeSorted.Length, ToBeSorted);
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: redk94/CodeBreaker
        static void Main(string[] args)
        {
            const int sizeOfArray = 10;

            int[] numbers;

            //numbers = GetRandomNumberList(sizeOfArray);
            numbers = new int[] { 5, 3, 7, 6, 2, 1, 4 };

            DisplayList("--Init: ", numbers);

            ISortable sorter = GetSorter(eSorter.Quick);

            numbers = sorter.Sort(numbers, eOrderBy.Asc);

            DisplayList("Sorted: ", numbers);
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: agiglio71/IBL
        //static void DoUno()
        //{
        //    Mammifero mammiferoTest = new Mammifero(); non posso farla

        //    Cane cane = new Cane(6, 4);
        //    cane.Stampa();

        //    Mammifero mammifero = cane;
        //    mammifero.Stampa();

        //    Cane cane2 = (Cane)mammifero;
        //    cane2.Stampa();

        //    Console.ReadLine();

        //    Orso orso = new Orso("mangia miele", 2);
        //    orso.Stampa();

        //    mammifero = orso;
        //    mammifero.Stampa();

        //    Console.ReadLine();

        //    List<Mammifero> animali = new List<Mammifero>
        //    {
        //        new Cane(6, 4),
        //        new Orso("mangia miele", 2)
        //    };

        //    animali.ForEach(animale => animale.Stampa());

        //    Console.ReadLine();
        //}

        static void DoDue()
        {
            DocumentoSpeciale documentoSpeciale = new DocumentoSpeciale();
            IFindable         findableSpeciale  = documentoSpeciale;
            ISortable         sortableSpeciale  = documentoSpeciale;
            IPrintable        printableSpeciale = documentoSpeciale;
            Documento         documento         = documentoSpeciale;
            IFindable         findable          = documento;
            ISortable         sortable          = documento;
            IPrintable        printable         = documento;

            documentoSpeciale.Find();
            findableSpeciale.Find();
            documento.Find();
            findable.Find();

            Console.WriteLine();

            documentoSpeciale.Sort();
            sortableSpeciale.Sort();
            documento.Sort();
            sortable.Sort();

            Console.WriteLine();

            //documentoSpeciale.Print();
            printableSpeciale.Print();
            //documento.Print();
            printable.Print();

            Console.ReadLine();

            Documento  documento2 = new Documento();
            IFindable  findable2  = documento2;
            ISortable  sortable2  = documento2;
            IPrintable printable2 = documento2;

            documento2.Find();
            findable2.Find();
            documento2.Sort();
            sortable2.Sort();
            //documento2.Print();
            printable2.Print();
            Console.ReadLine();
        }
コード例 #8
0
        public override bool Execute(CountInput input)
        {
            string inputFileName  = input.InputFileName;
            string outputFileName = input.OutputFileName;

            IReadable reader = DependencyResolver.Container.GetInstance <IReadable>(
                new ExplicitArguments()
                .Set(inputFileName));

            ISortable sorter = DependencyResolver.Container.GetInstance <ISortable>();

            IPrintable printer = DependencyResolver.Container.GetInstance <IPrintable>(
                new ExplicitArguments()
                .Set(outputFileName)
                .Set(sorter.Sort(reader.Read())));

            printer.Print();

            return(true);
        }
コード例 #9
0
        public static void LoadColumnSettings(Container container, WindowSettings settings)
        {
            foreach (ListView grid in ComponentHelper.GetChildWidgetsByType <ListView> (container))
            {
                Column   sortedColumn = null;
                ListView local        = grid;
                List <ColumnSettings> columnSettings = settings.Columns.FindAll(p => p.Owner == local.Name);
                List <Column>         gridColumns    = new List <Column> (grid.ColumnController);

                foreach (ColumnSettings columnSetting in columnSettings)
                {
                    string key        = columnSetting.Key;
                    Column gridColumn = gridColumns.Find(c => c.ListCell.PropertyName == key);
                    if (gridColumn == null)
                    {
                        continue;
                    }

                    gridColumn.IsSortable    = columnSetting.IsSortable;
                    gridColumn.SortDirection = columnSetting.SortDirection;
                    gridColumn.SortKey       = columnSetting.SortKey;
                    gridColumn.Width         = columnSetting.Width;
                    if (gridColumn.SortDirection != SortDirection.None)
                    {
                        sortedColumn = gridColumn;
                    }
                }

                if (sortedColumn == null || !sortedColumn.IsSortable)
                {
                    continue;
                }

                ISortable sortable = grid.Model as ISortable;
                if (sortable != null)
                {
                    sortable.Sort(sortedColumn);
                }
            }
        }
コード例 #10
0
ファイル: Program.cs プロジェクト: bhay3s/DesignPatterns
        static void Main(string[] args)
        {
            var Names = new List <string> {
                "BOB", "JON", "BILL"
            };
            ISortable strategy = SortStrategyFactory.GetSortStrategy(SortType.Bubble);

            strategy.Sort(Names);

            var Ages = new List <int> {
                23, 73, 88
            };
            ISortable strategy2 = SortStrategyFactory.GetSortStrategy(SortType.Merge);

            strategy2.Sort(Ages);

            var Directions = new List <string> {
                "North", "South", "East", "West"
            };
            ISortable strategy3 = SortStrategyFactory.GetSortStrategy(SortType.Quick);

            strategy3.Sort(Directions);
        }
コード例 #11
0
        protected virtual void OnColumnLeftClicked(Column clickedColumn)
        {
            if (Model is ISortable && clickedColumn is ISortableColumn)
            {
                ISortableColumn sort_column = clickedColumn as ISortableColumn;
                ISortable       sortable    = Model as ISortable;

                // Change the sort-type with every click
                if (sort_column == ColumnController.SortColumn)
                {
                    switch (sort_column.SortType)
                    {
                    case SortType.Ascending:    sort_column.SortType = SortType.Descending; break;

                    case SortType.Descending:   sort_column.SortType = SortType.None; break;

                    case SortType.None:         sort_column.SortType = SortType.Ascending; break;
                    }
                }

                // If we're switching from a different column, or we aren't reorderable, make sure sort type isn't None
                if ((sort_column != ColumnController.SortColumn || !IsEverReorderable) && sort_column.SortType == SortType.None)
                {
                    sort_column.SortType = SortType.Ascending;
                }

                sortable.Sort(sort_column);
                ColumnController.SortColumn = sort_column;
                IsReorderable = sortable.SortColumn == null || sortable.SortColumn.SortType == SortType.None;

                Model.Reload();
                CenterOnSelection();
                RecalculateColumnSizes();
                RegenerateColumnCache();
                InvalidateHeader();
            }
        }
コード例 #12
0
        private void buttonSort_Click(object sender, EventArgs e)
        {
            this.tmp.CopyTo(array, 0);
            int tmp = _radioButtonList.FindIndex(button => button.Checked);

            switch (tmp)
            {
            case 0:
            {
                _comparator = new NumberComparator();
                _sortable   = new BubbleSorter <double>();
            }
            break;

            case 1:
            {
                _comparator = new NumberComparator();
                _sortable   = new FlagBubble <double>();
            }
            break;

            case 2:
            {
                _comparator = new NumberComparator();
                _sortable   = new SimpleSelection <double>();
            }
            break;

            case 3:
            {
                _comparator = new NumberComparator();
                _sortable   = new QuickSort <double>();
            }
            break;

            case 4:
            {
                IComparableLab <CustomDoubleArray> comparator = new CustomDoubleArrayComparator();
                ISortable <CustomDoubleArray>      sortable   = new ShellSort <CustomDoubleArray>();
                if (sortable.ArrayCheck(CustomDoubleArray, comparator))
                {
                    tmpArrayHolder.Text    = "";
                    sortedArrayHolder.Text = "";

                    CustomDoubleArray = sortable.Sort(CustomDoubleArray, tmpArrayHolder, comparator, true, true);
                    sortable.Print(CustomDoubleArray, sortedArrayHolder, "");
                }
                else
                {
                    tmpLabel.Text = "Please reenter array, because it does not fit the condition!!";
                }
            }
                return;

            case 5:
            {
                _comparator = new NumberComparator();
                _sortable   = new MergeSort <double>();
                _direction  = false;
            }
            break;

            case 6:
            {
                int [] intArray = new int[array.Length];
                for (int i = 0; i < intArray.Length; i++)
                {
                    intArray[i] = (int)array[i];
                }

                intArray = Lab6ArrayHandler.Execute(intArray);
                IComparableLab <int> comparable = new NumberComparator();
                ISortable <int>      sortable   = new CountSort <int>();
                _direction = false;
                if (sortable.ArrayCheck(intArray, comparable))
                {
                    tmpArrayHolder.Text    = "";
                    sortedArrayHolder.Text = "";
                    sortable.Print(intArray, tmpArrayHolder, "Масив після виконання індивідуального завдання: \n");
                    intArray = sortable.Sort(intArray, tmpArrayHolder, comparable, _direction, true);
                    sortable.Print(intArray, sortedArrayHolder, "");
                }
                else
                {
                    tmpLabel.Text = "Please reenter array, because it does not fit the condition!!";
                }
            }
                return;

            default:
            {
                throw new IndexOutOfRangeException();
            }
            }

            if (_sortable.ArrayCheck(array, _comparator))
            {
                tmpArrayHolder.Text    = "";
                sortedArrayHolder.Text = "";

                array = _sortable.Sort(array, tmpArrayHolder, _comparator, _direction, true);
                _sortable.Print(array, sortedArrayHolder, "");
            }
            else
            {
                tmpLabel.Text = "Please reenter array, because it does not fit the condition!!";
            }
        }
コード例 #13
0
 public static void MSort <T>(this ISortable <T> aSet, Comparison <T> aComparison)
 {
     aSet.Sort(new CComparer <T>(aComparison));
 }
コード例 #14
0
ファイル: Program.cs プロジェクト: Meowse/student1
 private static void SortTheList(ISortable unsortedList)
 {
     unsortedList.Sort();
 }
コード例 #15
0
ファイル: Strategy.cs プロジェクト: ivan-borodiei/Education
 public void Sort()
 {
     sortAlgorytm.Sort <T>(collection);
 }
コード例 #16
0
 public static IQueryable <T> Sort <T>(this IQueryable <T> input, ISortable <T> filter)
 {
     return(filter.Sort(input));
 }
コード例 #17
0
 public void Sort()
 {
     array = SortBehaviour.Sort(array);
 }
コード例 #18
0
 public void InvokeSort()
 {
     _sortStrategy.Sort();
 }
コード例 #19
0
ファイル: Sort.cs プロジェクト: vh-vahan/ngenerics
        public void ExceptionInterface()
        {
            ISortable <GeneralTree <int> > tree = GetTestTree();

            Assert.Throws <NotSupportedException>(() => tree.Sort(null));
        }
コード例 #20
0
ファイル: Sort.cs プロジェクト: cxgr/ngenerics
        public void ExceptionInterface()
        {
            ISortable <GeneralTree <int> > tree = GetTestTree();

            tree.Sort(null);
        }
 public void BubbleSort(int[,] array, ISortable sortMethod, Direction d)
 => sortMethod.Sort(array, d);