Example #1
0
        /// <summary>
        /// 排序(1、冒泡排序。2、选择排序。3、插入排序。4、归并排序。5、快速排序)
        /// </summary>
        /// <param name="iCompareable">比较方法(T1比T2小为真,否则返回假)</param>
        public void Sort(Func <T, T, bool> iCompareable)
        {
            SortPattern eSortPattern = SortPattern.Quick;

            if (_iCount <= 10)
            {
                eSortPattern = SortPattern.Insert;
            }

            switch (eSortPattern)
            {
            case SortPattern.Bubble:
                BubbleSort(iCompareable);
                break;

            case SortPattern.Insert:
                InsertSort(iCompareable);
                break;

            case SortPattern.Merge:
                MergeSort(iCompareable);
                break;

            case SortPattern.Quick:
                QuickSort(iCompareable);
                break;

            case SortPattern.Select:
                SelectSort(iCompareable);
                break;
            }
        }
Example #2
0
        internal void PrimarySort_ByNameDescending_equals()
        {
            IEnumerable <FileInfo> files = new[]
            {
                new FileInfo(@"C:\1.txt"),
                new FileInfo(@"C:\3.txt"),
                new FileInfo(@"C:\4.txt"),
                new FileInfo(@"C:\2.txt"),
            };
            IEnumerable <FileInfo> expected = new[]
            {
                new FileInfo(@"C:\4.txt"),
                new FileInfo(@"C:\3.txt"),
                new FileInfo(@"C:\2.txt"),
                new FileInfo(@"C:\1.txt"),
            };
            var pattern = new SortPattern(SortPattern.SortPatternType.Name, true);
            var sorted  = pattern.PrimarySort(files);

            for (int i = 0; i < sorted.Count(); i++)
            {
                Assert.Equal(sorted.ElementAt(i).Name, expected.ElementAt(i).Name);
            }
        }