当前位置: 首页>>代码示例>>C#>>正文


C# SortableCollection.Sort方法代码示例

本文整理汇总了C#中SortableCollection.Sort方法的典型用法代码示例。如果您正苦于以下问题:C# SortableCollection.Sort方法的具体用法?C# SortableCollection.Sort怎么用?C# SortableCollection.Sort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SortableCollection的用法示例。


在下文中一共展示了SortableCollection.Sort方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

    static void Main()
    {
        var collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
        Console.WriteLine("All items before sorting:");
        Console.WriteLine(collection);

        Console.WriteLine("SelectionSorter result:");
        collection.Sort(new SelectionSorter<int>());
        Console.WriteLine(collection);

        Console.WriteLine("Quicksorter result:");
        collection.Sort(new Quicksorter<int>());
        Console.WriteLine(collection);

        Console.WriteLine("MergeSorter result:");
        collection.Sort(new MergeSorter<int>());
        Console.WriteLine(collection);

        Console.WriteLine("Linear search 101:");
        Console.WriteLine(collection.LinearSearch(101));

        Console.WriteLine("Binary search 101:");
        Console.WriteLine(collection.BinarySearch(101));

        Console.WriteLine("Shuffle:");
        collection.Shuffle();
        Console.WriteLine(collection);

        Console.WriteLine("Shuffle again:");
        collection.Shuffle();
        Console.WriteLine(collection);
    }
开发者ID:dgrigorov,项目名称:TelerikAcademy-1,代码行数:32,代码来源:Program.cs

示例2: Main

        internal static void Main(string[] args)
        {
            var collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
            Console.WriteLine("All items before sorting:");
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            Console.WriteLine("SelectionSorter result:");
            collection.Sort(new SelectionSorter<int>());
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            Console.WriteLine("BubbleSorter result:");
            collection.Sort(new BubbleSorter<int>());
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            Console.WriteLine("InsertionSorter result:");
            collection.Sort(new InsertionSorter<int>());
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
            Console.WriteLine("QuickSorter result:");
            collection.Sort(new QuickSorter<int>());
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
            Console.WriteLine("MergeSorter result:");
            collection.Sort(new MergeSorter<int>());
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            /*Console.WriteLine("Linear search 101:");
            Console.WriteLine(collection.LinearSearch(101));
            Console.WriteLine();

            Console.WriteLine("Binary search 101:");
            Console.WriteLine(collection.BinarySearch(101));
            Console.WriteLine();

            Console.WriteLine("Shuffle:");
            collection.Shuffle();
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            Console.WriteLine("Shuffle again:");
            collection.Shuffle();
            collection.PrintAllItemsOnConsole();*/
        }
开发者ID:MarinMarinov,项目名称:Data-structures-and-algorithms,代码行数:51,代码来源:Program.cs

示例3: Test3SectionSortMethod

 public void Test3SectionSortMethod()
 {
     var collection1 = new SortableCollection<string>(new[] { "aaaa", "cccc", "dddd", "cccc", "caaa", "aacc", "bbdd", "ccff", "eerr", "rrtt", "assdd" });
     collection1.Sort(new SelectionSorter<string>());
     var testCollection = new SortableCollection<int>(new[] { -55, -12, 13, 22, 23, 44, 45, 55, 90, 100, 101 });
     Assert.Equals(testCollection, collection1);
 }
开发者ID:KTsolev,项目名称:SortringAlgoritmsHomework,代码行数:7,代码来源:UnitTest1.cs

示例4: Main

        public static void Main(string[] args)
        {
            const int NumberOfElementsToSort = 22;
            const int MaxValue = 150;

            var array = new int[NumberOfElementsToSort];

            for (int i = 0; i < NumberOfElementsToSort; i++)
            {
                array[i] = Random.Next(MaxValue);
            }

            var collectionToSort = new SortableCollection<int>(array);
            collectionToSort.Sort(new BucketSorter { Max = MaxValue });

            Console.WriteLine(collectionToSort);

            var collectionToShuffle = new SortableCollection<int>(1, 2, 3, 4, 5);
            Console.WriteLine("Before shufflin` " + collectionToShuffle);
            collectionToShuffle.Shuffle();
            Console.WriteLine("After shufflin` " + collectionToShuffle);

            var collection = new SortableCollection<int>(2, -1, 5, 0, -3);
            Console.WriteLine(collection);

            // collection.Sort(new Quicksorter<int>());
            collection.Sort(new InsertionSorter<int>());
            Console.WriteLine(collection);
        }
开发者ID:aanguelov,项目名称:AlgorithmsHomeworks,代码行数:29,代码来源:SortableCollectionPlayground.cs

示例5: Main

        public static void Main(string[] args)
        {
            const int NumberOfElementsToSort = 22;
            const int MaxValue = 150;

            var array = new int[NumberOfElementsToSort];

            for (int i = 0; i < NumberOfElementsToSort; i++)
            {
                array[i] = Random.Next(MaxValue);
            }

            var collectionToSort = new SortableCollection<int>(array);
            // !!!!!!!!!!!!!! collectionToSort.Sort(new BucketSorter { Max = MaxValue });

            Console.WriteLine(collectionToSort);

            var collection = new SortableCollection<int>(2, -1, 5, 0, -3);
            Console.WriteLine(collection);

            // collection.Sort(new Quicksorter<int>());
            collection.Sort(new InsertionSorter<int>());
            Console.WriteLine(collection);

            Console.WriteLine(collection.InterpolationSearch(0));
        }
开发者ID:flyer87,项目名称:Alghoritms,代码行数:26,代码来源:SortableCollectionPlayground.cs

示例6: TestSelectionSortingWithEmptyCollection

        public void TestSelectionSortingWithEmptyCollection()
        {
            var collection = new SortableCollection<int>();
            collection.Sort(new SelectionSorter<int>());

            Assert.AreEqual(0, collection.Items.Count, "Collection is not empty after sorting");
        }
开发者ID:kiko81,项目名称:Teleric-Academy-Homeworks,代码行数:7,代码来源:SelectionSortTests.cs

示例7: MergeSortShouldWorkCorrectlyWithEmptyCollection

        public void MergeSortShouldWorkCorrectlyWithEmptyCollection()
        {
            var collection = new SortableCollection<int>();
            collection.Sort(new MergeSorter<int>());

            Assert.AreEqual(0, collection.Items.Count, "Collection is not empty after sorting!");
        }
开发者ID:MarinaGeorgieva,项目名称:TelerikAcademy,代码行数:7,代码来源:MergeSorterTests.cs

示例8: Test1SectionSortMethod

 public void Test1SectionSortMethod()
 {
     var collection = new SortableCollection<int>(new[] { 22, 13 });
     collection.Sort(new SelectionSorter<int>());
     var testCollection = new SortableCollection<int>(new[] { 13, 22 });
     Assert.Equals(collection,testCollection);
 }
开发者ID:KTsolev,项目名称:SortringAlgoritmsHomework,代码行数:7,代码来源:UnitTest1.cs

示例9: Test2SectionSortMethod

 public void Test2SectionSortMethod()
 {
     var collection1 = new SortableCollection<int>(new[] { 22, 13, 23, 45, -55, 90, 100, 101, -12, 55, 44 });
     collection1.Sort(new SelectionSorter<int>());
     var testCollection = new SortableCollection<int>(new[] { -55, -12, 13, 22, 23, 44, 45, 55, 90, 100, 101 });
     Assert.Equals(testCollection, collection1);
 }
开发者ID:KTsolev,项目名称:SortringAlgoritmsHomework,代码行数:7,代码来源:UnitTest1.cs

示例10: TestSortWithMultipleElementsMultipleTimes

        public void TestSortWithMultipleElementsMultipleTimes()
        {
            const int NumberOfAttempts = 10000;
            const int MaxNumberOfElements = 1000;

            for (int i = 0; i < NumberOfAttempts; i++)
            {
                var numberOfElements = Random.Next(0, MaxNumberOfElements + 1);

                List<int> originalElements = new List<int>(MaxNumberOfElements);

                for (int j = 0; j < numberOfElements; j++)
                {
                    originalElements.Add(Random.Next(int.MinValue, int.MaxValue));
                }

                var collection = new SortableCollection<int>(originalElements);

                originalElements.Sort();
                collection.Sort(TestSorter);

                CollectionAssert.AreEqual(
                    originalElements,
                    collection.ToArray(),
                    "Sort method should sort the elements in ascending order.");
            }
        }
开发者ID:vangelov-i,项目名称:Fundamentals,代码行数:27,代码来源:SortTests.cs

示例11: SelectionSorterTestWithOneElement

 public void SelectionSorterTestWithOneElement()
 {
     SortableCollection<int> collection = new SortableCollection<int>(new int[] { 5 });
     collection.Sort(new SelectionSorter<int>());
     Assert.AreEqual(1, collection.Items.Count);
     Assert.AreEqual(5, collection.Items[0]);
 }
开发者ID:bahtev,项目名称:TelerikAcademy,代码行数:7,代码来源:SelectionSorterTest.cs

示例12: Main

        public static void Main(string[] args)
        {
            const int NumberOfElementsToSort = 22;
            const int MaxValue = 150;

            var array = new int[NumberOfElementsToSort];

            for (int i = 0; i < NumberOfElementsToSort; i++)
            {
                array[i] = Random.Next(MaxValue);
            }

            var collectionToSort = new SortableCollection<int>(array);

            collectionToSort.Sort(new BucketSorter { Max = MaxValue });
            Console.WriteLine(collectionToSort);

            var collection = new SortableCollection<int>(2, -1, 5, 0, -3);
            collection = new SortableCollection<int>(3, 44, 38, 5, 47, 15, 36, 26, 27, 2, 46, 4, 19, 50, 48);
            Console.WriteLine(collection);

            collection.Shuffle();
            Console.WriteLine(collection);

            //collection.Sort(new Quicksorter<int>());
            //Console.WriteLine(collection);
        }
开发者ID:ttitto,项目名称:DataStructuresAndAlgorithms,代码行数:27,代码来源:SortableCollectionPlayground.cs

示例13: BinarySearchShouldWorkCorrectlyWhenSearchedElementIsNotFound

        public void BinarySearchShouldWorkCorrectlyWhenSearchedElementIsNotFound()
        {
            var collection = new SortableCollection<int>(new int[] { 6, 1, 4, 2, 3, -5, 8 });
            collection.Sort(new MergeSorter<int>());
            var found = collection.BinarySearch(21);

            Assert.IsFalse(found, "Element is found in collection!");
        }
开发者ID:MarinaGeorgieva,项目名称:TelerikAcademy,代码行数:8,代码来源:BinarySearchTests.cs

示例14: TestBinarySearchResultIsLast

 public void TestBinarySearchResultIsLast()
 {
     int[] input = { 8, 5, 8, 3, 4, 67, 9, 3, 9, -4 };
     SortableCollection<int> sortableCol = new SortableCollection<int>(input);
     sortableCol.Sort(new MergeSorter<int>());
     bool containsItem = sortableCol.BinarySearch(-4);
     Assert.IsTrue(containsItem);
 }
开发者ID:ilkodzhambazov,项目名称:Telerik-Academy,代码行数:8,代码来源:SearchingTests.cs

示例15: LinearSearchShouldWorkCorrectlyWithEmptyCollection

        public void LinearSearchShouldWorkCorrectlyWithEmptyCollection()
        {
            var collection = new SortableCollection<int>();
            collection.Sort(new MergeSorter<int>());
            var found = collection.LinearSearch(21);

            Assert.IsFalse(found, "Element is found in empty collection!");
        }
开发者ID:MarinaGeorgieva,项目名称:TelerikAcademy,代码行数:8,代码来源:LinearSearchTests.cs


注:本文中的SortableCollection.Sort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。