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


C# SortableCollection.InterpolationSearch方法代码示例

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


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

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

示例2: TestWithItemToTheRightOfMidpoint

        public void TestWithItemToTheRightOfMidpoint()
        {
            var collection = new SortableCollection<int>(1, 2, 3, 4, 5);

            var result = collection.InterpolationSearch(4);
            var expected = Array.BinarySearch(collection.ToArray(), 4);

            Assert.AreEqual(expected, result);
        }
开发者ID:iliankostov,项目名称:Algorithms,代码行数:9,代码来源:InterpolationSearchTests.cs

示例3: TestWithEmptyCollectionShouldReturnMissingElement

        public void TestWithEmptyCollectionShouldReturnMissingElement()
        {
            var collection = new SortableCollection<int>();

            var result = collection.InterpolationSearch(0);
            var expected = Array.BinarySearch(collection.ToArray(), 0);

            Assert.AreEqual(expected, result, "No elements are present in an empty collection; method should return -1.");
        }
开发者ID:ivan4otopa,项目名称:SoftUni,代码行数:9,代码来源:InterpolationSearchTests.cs

示例4: InterpolationTest5

        public void InterpolationTest5()
        {
            var collection = new SortableCollection<int>(1, 2, 3, 4, 5);

            var result = collection.InterpolationSearch(4);
            var expected = Array.BinarySearch(collection.ToArray(), 4);

            Assert.AreEqual(expected, result);
        }
开发者ID:sideroff,项目名称:Softuni,代码行数:9,代码来源:InterpolationSearchTests.cs

示例5: TestWithItemAtMidpoint

        public void TestWithItemAtMidpoint()
        {
            var collection = new SortableCollection<int>(1, 2, 3, 4, 5);
            this.ApplyDelegates(ref collection);
            var result = collection.InterpolationSearch(3);
            var expected = Array.BinarySearch(collection.ToArray(), 3);

            Assert.AreEqual(expected, result);
        }
开发者ID:EBojilova,项目名称:Algorithms-CSharp,代码行数:9,代码来源:InterpolationSearchTests.cs

示例6: TestWithMissingElement

        public void TestWithMissingElement()
        {
            var collection = new SortableCollection<int>(-1, 1, 5, 12, 50);

            var result = collection.InterpolationSearch(0);
            var expected = -1;

            Assert.AreEqual(expected, result, "Missing element should return -1.");
        }
开发者ID:iliankostov,项目名称:Algorithms,代码行数:9,代码来源:InterpolationSearchTests.cs

示例7: TestWithItemAtMidpoint

        public void TestWithItemAtMidpoint()
        {
            var collection = new SortableCollection<int>(1, 2, 3, 4, 5);
            var items = collection.Items;

            var result = collection.InterpolationSearch(items, 3, interpolator);
            var expected = Array.BinarySearch(collection.ToArray(), 3);

            Assert.AreEqual(expected, result);
        }
开发者ID:pavelilchev,项目名称:HomeWorks,代码行数:10,代码来源:InterpolationSearchTests.cs

示例8: TestWithItemToTheLeftOfMidpoint

        public void TestWithItemToTheLeftOfMidpoint()
        {
            var collection = new SortableCollection<int>(1, 2, 3, 4, 5);

            var sorter = new Quicksorter<int>();
            collection.Sort(sorter);
            var result = collection.InterpolationSearch(collection.ToArray(), 2);
            var expected = Array.BinarySearch(collection.ToArray(), 2);

            Assert.AreEqual(expected, result);
        }
开发者ID:pkanev,项目名称:Data.Structures,代码行数:11,代码来源:InterpolationSearchTests.cs

示例9: TestWithEmptyCollectionShouldReturnMissingElement

        public void TestWithEmptyCollectionShouldReturnMissingElement()
        {
            var collection = new SortableCollection<int>();
            // the idea for the delegates is given from ttitto
            this.ApplyDelegates(ref collection);
            var result = collection.InterpolationSearch(0);
            var expected = Array.BinarySearch(collection.ToArray(), 0);

            Assert.AreEqual(
                expected,
                result,
                "No elements are present in an empty collection; method should return -1.");
        }
开发者ID:EBojilova,项目名称:Algorithms-CSharp,代码行数:13,代码来源:InterpolationSearchTests.cs

示例10: TestWithRepeatingItemShouldReturnFirstDiscoveredIndex

        public void TestWithRepeatingItemShouldReturnFirstDiscoveredIndex()
        {
            var collection = new SortableCollection<int>(0, 3, 3, 3, 3, 7, 7, 7, 7, 7, 7);
            var result = collection.InterpolationSearch(3);

            Assert.AreEqual(2, result);
        }
开发者ID:iliankostov,项目名称:Algorithms,代码行数:7,代码来源:InterpolationSearchTests.cs

示例11: TestWithMultipleMissingKeysSmallerThanMinimum

        public void TestWithMultipleMissingKeysSmallerThanMinimum()
        {
            const int NumberOfChecks = 10000;
            const int NumberOfElements = 1000;

            var elements = new int[NumberOfElements];

            for (int i = 0; i < NumberOfElements; i++)
            {
                elements[i] = Random.Next(int.MinValue / 2, int.MaxValue / 2);
            }

            Array.Sort(elements);

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

            for (int i = 0; i < NumberOfChecks; i++)
            {
                var item = Random.Next(int.MinValue, collection.Items[0]);

                int result = collection.InterpolationSearch(item);

                Assert.AreEqual(-1, result);
            }
        }
开发者ID:iliankostov,项目名称:Algorithms,代码行数:25,代码来源:InterpolationSearchTests.cs

示例12: InterpolationTest9

        public void InterpolationTest9()
        {
            var collection = new SortableCollection<int>(0, 3, 3, 3, 3, 7, 7, 7, 7, 7, 7);
            var result = collection.InterpolationSearch(3);

            Assert.IsTrue(new int[] { 1, 2, 3, 4 }.Contains(result));
        }
开发者ID:sideroff,项目名称:Softuni,代码行数:7,代码来源:InterpolationSearchTests.cs

示例13: TestWithRepeatingItemShouldReturnFirstDiscoveredIndex

        public void TestWithRepeatingItemShouldReturnFirstDiscoveredIndex()
        {
            var collection = new SortableCollection<int>(0, 3, 3, 3, 3, 7, 7, 7, 7, 7, 7);
            var sorter = new InsertionSorter<int>();
            collection.Sort(sorter);
            var sortedArray = collection.ToArray(); 
            var result = collection.InterpolationSearch(sortedArray, 3);

            Assert.AreEqual(4, result);
        }
开发者ID:pkanev,项目名称:Data.Structures,代码行数:10,代码来源:InterpolationSearchTests.cs

示例14: TestWithMultipleMissingKeysLargerThanMaximum

        public void TestWithMultipleMissingKeysLargerThanMaximum()
        {
            const int NumberOfChecks = 10000;
            const int NumberOfElements = 1000;

            var elements = new int[NumberOfElements];

            for (int i = 0; i < NumberOfElements; i++)
            {
                elements[i] = Random.Next(int.MinValue / 2, int.MaxValue / 2);
            }

            Array.Sort(elements);

            var collection = new SortableCollection<int>(elements);
            var sorter = new Quicksorter<int>();
            collection.Sort(sorter);
            var sortedArray = collection.ToArray();

            for (int i = 0; i < NumberOfChecks; i++)
            {
                var item = Random.Next(collection.Items[collection.Count - 1], int.MaxValue);
                
                var result = collection.InterpolationSearch(sortedArray, item);

                Assert.AreEqual(-1, result);
            }
        }
开发者ID:pkanev,项目名称:Data.Structures,代码行数:28,代码来源:InterpolationSearchTests.cs

示例15: TestWithMultipleKeys

        public void TestWithMultipleKeys()
        {
            const int NumberOfElements = 10000;

            var elements = new int[NumberOfElements];

            for (int i = 0; i < NumberOfElements; i++)
            {
                elements[i] = Random.Next(-100, 100);
            }

            Array.Sort(elements);

            var collection = new SortableCollection<int>(elements);
            var items = collection.Items;

            foreach (var element in elements)
            {
                var result = collection.InterpolationSearch(items, element, interpolator);

                Assert.AreEqual(element, items[result]);
            }
        }
开发者ID:pavelilchev,项目名称:HomeWorks,代码行数:23,代码来源:InterpolationSearchTests.cs


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