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


C# SortableCollection.BinarySearch方法代码示例

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


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

示例1: MethodShouldReturnFalseWhenItemDoesnotExists

        public void MethodShouldReturnFalseWhenItemDoesnotExists()
        {
            var collection = new SortableCollection<int>(new[] { 52, 111, 33, 33, 46, 1125, 1 });

            Assert.IsFalse(collection.BinarySearch(1111));
            Assert.IsFalse(collection.BinarySearch(-52));
            Assert.IsFalse(collection.BinarySearch(0));
        }
开发者ID:NikitoG,项目名称:TelerikAcademyHomeworks,代码行数:8,代码来源:BinarySearchTests.cs

示例2: TesBinarySearchtWithEmptyCollection

 public void TesBinarySearchtWithEmptyCollection()
 {
     SortableCollection<int> collection = new SortableCollection<int>();
     bool result = collection.BinarySearch(15);
     Assert.IsFalse(result);
     result = collection.BinarySearch(0);
     Assert.IsFalse(result);
     result = collection.BinarySearch(-1);
     Assert.IsFalse(result);
 }
开发者ID:bahtev,项目名称:TelerikAcademy,代码行数:10,代码来源:BinarySearchTest.cs

示例3: TestForSingleItem

 public void TestForSingleItem()
 {
     SortableCollection<string> collection = new SortableCollection<string>(
         new List<string>() { "1" });
     Assert.IsTrue(collection.LinearSearch("1"), "Linear search failed on single item collection");
     Assert.IsTrue(collection.BinarySearch("1"), "Binary search failed on single item collection");
     Assert.IsFalse(collection.LinearSearch("2"),
         "Linear search failed on single item collection - non-existing item");
     Assert.IsFalse(collection.BinarySearch("2"),
         "Binary search failed on single item collection - non-existing item");
 }
开发者ID:psotirov,项目名称:TelerikAcademyProjects,代码行数:11,代码来源:TestSearches.cs

示例4: TestForOddItems

 public void TestForOddItems()
 {
     SortableCollection<string> collection = new SortableCollection<string>(
         new List<string>() { "5", "1", "4", "1", "6" });
     Assert.IsTrue(collection.LinearSearch("1"), "Linear search failed on odd items collection");
     collection.Sort(new SelectionSorter<string>());
     Assert.IsTrue(collection.BinarySearch("1"), "Binary search failed on odd items collection");
     Assert.IsFalse(collection.LinearSearch("2"),
         "Linear search failed on odd items collection - non-existing item");
     Assert.IsFalse(collection.BinarySearch("2"),
         "Binary search failed on odd items collection - non-existing item");
 }
开发者ID:psotirov,项目名称:TelerikAcademyProjects,代码行数:12,代码来源:TestSearches.cs

示例5: TesBinarySearchtWithOneMissingElement

        public void TesBinarySearchtWithOneMissingElement()
        {
            SortableCollection<int> collection = new SortableCollection<int>(
                new int[] { 3 });

            bool result = collection.BinarySearch(15);
            Assert.IsFalse(result);
            result = collection.BinarySearch(0);
            Assert.IsFalse(result);
            result = collection.BinarySearch(-1);
            Assert.IsFalse(result);
        }
开发者ID:bahtev,项目名称:TelerikAcademy,代码行数:12,代码来源:BinarySearchTest.cs

示例6: TesBinarySearchTrivialCase

        public void TesBinarySearchTrivialCase()
        {
            SortableCollection<int> collection = new SortableCollection<int>(
                new int[] { -33, -21, 0, 1, 2, 2, 4, 5, 6, 7, 12, 15 });

            bool result = collection.BinarySearch(2);
            Assert.IsTrue(result);
            result = collection.BinarySearch(4);
            Assert.IsTrue(result);
            result = collection.BinarySearch(5);
            Assert.IsTrue(result);
            result = collection.BinarySearch(6);
            Assert.IsTrue(result);
        }
开发者ID:bahtev,项目名称:TelerikAcademy,代码行数:14,代码来源:BinarySearchTest.cs

示例7: BinarySearchShouldWorkCorrectlyWithEmptyCollection

        public void BinarySearchShouldWorkCorrectlyWithEmptyCollection()
        {
            var collection = new SortableCollection<int>();
            var found = collection.BinarySearch(21);

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

示例8: TestBinarySearchWithExistingRepeatingElementInCollection

        public void TestBinarySearchWithExistingRepeatingElementInCollection()
        {
            var collection = new SortableCollection<int>(new[] { 101, 101, 33, 22, 11, 0 });
            var result = collection.BinarySearch(101);

            Assert.IsTrue(result, "Element not found");
        }
开发者ID:zdzdz,项目名称:Data-Structures-and-Algorithms-HW,代码行数:7,代码来源:BinarySearchTests.cs

示例9: TestBinarySearchWithExistingElementInMiddlePositionOddCountOfElements

        public void TestBinarySearchWithExistingElementInMiddlePositionOddCountOfElements()
        {
            var collection = new SortableCollection<int>(new[] { 49, 101, 33, 22, 11, 0, 17 });
            var result = collection.BinarySearch(22);

            Assert.IsTrue(result, "Element not found");
        }
开发者ID:zdzdz,项目名称:Data-Structures-and-Algorithms-HW,代码行数:7,代码来源:BinarySearchTests.cs

示例10: TestBinarySearchWithExistingElementInFirstPositionEvenCountOfElements

        public void TestBinarySearchWithExistingElementInFirstPositionEvenCountOfElements()
        {
            var collection = new SortableCollection<int>(new[] { 49, 101, 33, 22, 11, 0 });
            var result = collection.BinarySearch(49);

            Assert.IsTrue(result, "Element not found");
        }
开发者ID:zdzdz,项目名称:Data-Structures-and-Algorithms-HW,代码行数:7,代码来源:BinarySearchTests.cs

示例11: TestBinarySearchWithEmptyCollection

        public void TestBinarySearchWithEmptyCollection()
        {
            var collection = new SortableCollection<int>();
            var result = collection.BinarySearch(101);

            Assert.IsFalse(result, "Element found in empty collection");
        }
开发者ID:zdzdz,项目名称:Data-Structures-and-Algorithms-HW,代码行数:7,代码来源:BinarySearchTests.cs

示例12: TestBinarySearchWithCollectionOfEqualElements

        public void TestBinarySearchWithCollectionOfEqualElements()
        {
            var collection = new SortableCollection<int>(new[] { 101, 101, 101, 101, 101 });
            var result = collection.BinarySearch(101);

            Assert.IsTrue(result, "Element not found");
        }
开发者ID:zdzdz,项目名称:Data-Structures-and-Algorithms-HW,代码行数:7,代码来源:BinarySearchTests.cs

示例13: 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

示例14: Main

        public static void Main()
        {
            List<int> numbers = new List<int>() {1,3,4,6,7,8,9,10,23,42};

            SortableCollection<int> sortableCollection = new SortableCollection<int>(numbers);
            Console.WriteLine(sortableCollection.BinarySearch(-12));
        }
开发者ID:hristo-iliev,项目名称:TelerikHW,代码行数:7,代码来源:BinarySearch.cs

示例15: 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("SelectionSorter result:");
            collection.Sort(new SelectionSorter<int>());
            collection.PrintAllItemsOnConsole();

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

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

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

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

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

            Console.WriteLine("Shuffle again:");
            collection.Shuffle();
            collection.PrintAllItemsOnConsole();
        }
开发者ID:jesconsa,项目名称:Telerik-Academy,代码行数:34,代码来源:Program.cs


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