Пример #1
0
        public void TestInterpolationSearch()
        {
            int[] arr = { 10, 12, 13, 16, 18, 19, 20, 21, 22, 23, 24, 33, 35, 42, 47 };

            arr = arr.OrderBy(c => c).ToArray();
            int x = 18;


            var actual   = search.Search(arr, x);
            var expected = 4;

            Assert.Equal(expected, actual);
        }
        public void Search()
        {
            //Arrange
            List <Node> list = new List <Node>
            {
                new Node(5),
                new Node(1),
                new Node(10),
                new Node(11)
            };
            InterpolationSearch s = new InterpolationSearch(list);
            //Act
            Node searchValue = new Node(11);
            var  result1     = s.Search(searchValue);

            searchValue = new Node(12);
            var result2 = s.Search(searchValue);

            //Assert
            Assert.AreEqual(true, result1);
            Assert.AreEqual(false, result2);
        }
Пример #3
0
        private static void InterpolationSearchCase()
        {
            Console.WriteLine("********************Interpolation Search*************************");
            string filePath = $@"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase)}";

            Console.WriteLine("Enter the sorted array string :");
            string test = Console.ReadLine();

            int[] input = JsonConvert.DeserializeObject <int[]>(test);
            Console.WriteLine("Enter the Search Value:");
            int value = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine(InterpolationSearch.Search(input, 0, input.Length - 1, value));
        }