public void Start()
        {
            #region LinearSearch

            var ls = new LinearSearch();
            TestAlgorithm("Linear Search", ls.Solution);

            #endregion

            #region BinarySearch

            var bs = new BinarySearch();
            TestAlgorithm("Binary Search", bs.Solution);
            CalcLatency("Binary FindFirst", bs.FindFirst, new int[] { 0, 1, 1, 2, 3, 4, 5, 5, 5, 5, 5, 6, 6, 7, 8, 9 }, 5);
            CalcLatency("Binary FindLast", bs.FindLast, new int[] { 0, 1, 1, 2, 3, 4, 5, 5, 5, 5, 5, 6, 6, 7, 8, 9 }, 5);
            CalcLatency("Binary CountOcurrences", bs.CountRepetitions, new int[] { 0, 1, 1, 2, 3, 4, 5, 5, 5, 5, 5, 6, 6, 7, 8, 9 }, 5);

            #endregion

            #region JumpSearch

            var js = new JumpSearch();
            TestAlgorithm("Jump Search", js.Solution);

            #endregion

            #region InterpolationSearch

            var @is = new InterpolationSearch();
            TestAlgorithm("Interpolation Search", @is.Solution);

            #endregion
        }
Пример #2
0
        public void InterpolationSearchTest()
        {
            InterpolationSearch <int> interpolationSearch = new InterpolationSearch <int>();

            for (int i = 0; i < 100; i++)
            {
                FillRandom();
                this.Items.Sort();

                interpolationSearch.Items.Clear();
                interpolationSearch.Items.AddRange(this.Items);

                if (this.Items.IndexOf(this.SearchItem) != -1 && interpolationSearch.ToFind(this.SearchItem) != -1)
                {
                    Assert.AreEqual(this.Items[this.Items.IndexOf(this.SearchItem)], this.Items[interpolationSearch.ToFind(this.SearchItem)]);
                }
                else
                if (interpolationSearch.ToFind(this.SearchItem) == -1 && this.Items.IndexOf(this.SearchItem) != -1)
                {
                    Assert.IsTrue(false);
                }
                else if (interpolationSearch.ToFind(this.SearchItem) != -1 && this.Items.IndexOf(this.SearchItem) == -1)
                {
                    Assert.IsTrue(false);
                }
                else if (interpolationSearch.ToFind(this.SearchItem) != -1 && this.Items.IndexOf(this.SearchItem) != -1)
                {
                    Assert.IsTrue(true);
                }
            }
        }
Пример #3
0
        public static void InterPolationSearchTest()
        {
            int    len   = 10;
            int    range = 1000;
            Random rnd   = new Random();

            int[] arr = new int[len];
            for (int i = 0; i < len; i++)
            {
                arr[i] = rnd.Next(range);
            }
            SimpleSort <int> .QuickSort(ref arr, len);

            foreach (int i in arr)
            {
                Console.Write("{0} ", i);
            }
            while (true)
            {
                Console.WriteLine("\n\n Search : ");
                int key;

                try { key = int.Parse(Console.ReadLine()); }
                catch { break; }

                Console.WriteLine("\nOk. Search {0}.", key);
                InterpolationSearch its = new InterpolationSearch(arr, key, (idx) => Console.WriteLine("The Index is {0}.", idx));
                its.Work();
                Console.WriteLine("-------------");
            }
        }
 public void Setup()
 {
     this.interpolationSearch = new InterpolationSearch();
     this.arrayGenerator      = new ArrayGenerator();
     this.arrayGenerator.AscendGenerator(this.Length);
     this.testArray = this.arrayGenerator.output;
 }
        public void InterpolationSearch_Find_NoFind()
        {
            var search = new InterpolationSearch();

            var list = new List <int>()
            {
                2, 4, 6
            };
            var result = search.Find(list, 5);

            Assert.IsNull(result.PositionFound);
        }
        public void InterpolationSearch_Find_FindFirst()
        {
            var search = new InterpolationSearch();

            var list = new List <int>()
            {
                2, 4, 6
            };
            var result = search.Find(list, 2);

            Assert.AreEqual(0, result.PositionFound);
        }
Пример #7
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));
        }
        public void GetStartIndex()
        {
            var values = new List <int> {
                3, 7, 10, 14, 21, 27, 27, 32, 38, 45, 53
            };

            Assert.AreEqual(39, InterpolationSearch.GetStartIndex(values, 200, 0, values.Count - 1));
            Assert.AreEqual(10, InterpolationSearch.GetStartIndex(values, 53, 0, values.Count - 1));
            Assert.AreEqual(0, InterpolationSearch.GetStartIndex(values, -1, 0, values.Count - 1));
            Assert.AreEqual(2, InterpolationSearch.GetStartIndex(values, 14, 0, values.Count - 1));
            Assert.AreEqual(4, InterpolationSearch.GetStartIndex(values, 27, 0, values.Count - 1));
            Assert.AreEqual(5, InterpolationSearch.GetStartIndex(values, 32, 0, values.Count - 1));
            Assert.AreEqual(0, InterpolationSearch.GetStartIndex(values, 7, 0, values.Count - 1));
            Assert.AreEqual(0, InterpolationSearch.GetStartIndex(values, 4, 0, values.Count - 1));
        }
        public void InterpolationSearchWorksCorrectly()
        {
            //Arrange
            int[] array = new int[] { -50, 3, 7, -125, 4, 0, -22, -178, 99, 120, -33, 9, 5, 2, 6, 1, 8, 10, 55, 110, 12, 34, 66 };
            Array.Sort(array);
            int numberToFind = 10;
            int position     = 15;
            var search       = new InterpolationSearch();

            //Act
            int result = search.InterpolationArraySearch(array, numberToFind);

            //Assert
            Assert.AreEqual(position, result);
        }
Пример #10
0
        static void Main(string[] args)
        {
            var fizzBuzz            = new FizzBuzz(); // start of js udemy algo
            var harmlessRansomNote  = new HarmlessRansomNote();
            var isPalinDrome        = new IsPalindrome();
            var reverseWords        = new ReverseWords();
            var caesarCiepher       = new CaesarCiepher();
            var reverseArrayInPlace = new ReverseArrayInPlace(); // end of js udemy algo
            var linearSearch        = new LinearSearch();        // https://www.geeksforgeeks.org/linear-search/
            var binarySearch        = new BinarySearch();        // https://www.geeksforgeeks.org/binary-search/
            var jumpSearch          = new JumpSearch();          // https://www.geeksforgeeks.org/jump-search/
            var interpolationSearch = new InterpolationSearch(); //  https://www.geeksforgeeks.org/interpolation-search/

            int x      = 18;                                     // Element to be searched
            var result = interpolationSearch.printAlgo(x);
        }
        public void InterpolationSearch_Find_FindMiddle()
        {
            var search = new InterpolationSearch();

            var list = new List <int>()
            {
                2, 4, 6
            };
            var result = search.Find(list, 4);

            Assert.AreEqual(1, result.PositionFound);

            list = new List <int>()
            {
                2, 4, 6, 8
            };
            result = search.Find(list, 6);
            Assert.AreEqual(2, result.PositionFound);
        }
        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);
        }
 public void InterpolationSearchTest(int[] array, int numberToFind, int expected) =>
 Assert.AreEqual(expected, InterpolationSearch.Execute(array, numberToFind));
Пример #14
0
        static void Main(string[] args)
        {
            int[]      arr_bs = { 7, 26, 53, 22, 32, 28, 38, 23, 24, 54, 27, 78, 33 };
            BubbleSort bs     = new BubbleSort();

            Console.WriteLine("冒泡排序:");
            bs.MyBulleSort(arr_bs);

            /*result
             *  7 26 22 32 28 38 23 24 53 27 54 33 78
             *  7 22 26 28 32 23 24 38 27 53 33 54 78
             *  7 22 26 28 23 24 32 27 38 33 53 54 78
             *  7 22 26 23 24 28 27 32 33 38 53 54 78
             *  7 22 23 24 26 27 28 32 33 38 53 54 78
             *  7 22 23 24 26 27 28 32 33 38 53 54 78
             *  7 22 23 24 26 27 28 32 33 38 53 54 78
             *  7 22 23 24 26 27 28 32 33 38 53 54 78
             *  7 22 23 24 26 27 28 32 33 38 53 54 78
             *  7 22 23 24 26 27 28 32 33 38 53 54 78
             *  7 22 23 24 26 27 28 32 33 38 53 54 78
             *  7 22 23 24 26 27 28 32 33 38 53 54 78
             *  程序的运行时间:0.0242318 秒
             */

            int[]     arr_qs = { 7, 26, 53, 22, 32, 28, 38, 23, 24, 54, 27, 78, 33 };
            QuickSort qs     = new QuickSort();

            Console.WriteLine("快速排序:");
            qs.MyQuickSort(arr_qs, 0, arr_qs.Length - 1);

            /*result
             *  7 26 53 22 32 28 38 23 24 54 27 78 33
             *  7 24 23 22 26 28 38 32 53 54 27 78 33
             *  7 22 23 24 26 28 38 32 53 54 27 78 33
             *  7 22 23 24 26 28 38 32 53 54 27 78 33
             *  7 22 23 24 26 27 28 32 53 54 38 78 33
             *  7 22 23 24 26 27 28 32 53 54 38 78 33
             *  7 22 23 24 26 27 28 32 33 38 53 78 54
             *  7 22 23 24 26 27 28 32 33 38 53 78 54
             *  7 22 23 24 26 27 28 32 33 38 53 54 78
             */

            int[]         arr_ins = { 7, 26, 53, 22, 32, 28, 38, 23, 24, 54, 27, 78, 33 };
            InsertionSort ins     = new InsertionSort();

            Console.WriteLine("插入排序:");
            ins.MyInsertionSort(arr_ins);

            /*result
             *  7 26 53 22 32 28 38 23 24 54 27 78 33
             *  7 26 53 22 32 28 38 23 24 54 27 78 33
             *  7 22 26 53 32 28 38 23 24 54 27 78 33
             *  7 22 26 32 53 28 38 23 24 54 27 78 33
             *  7 22 26 28 32 53 38 23 24 54 27 78 33
             *  7 22 26 28 32 38 53 23 24 54 27 78 33
             *  7 22 23 26 28 32 38 53 24 54 27 78 33
             *  7 22 23 24 26 28 32 38 53 54 27 78 33
             *  7 22 23 24 26 28 32 38 53 54 27 78 33
             *  7 22 23 24 26 27 28 32 38 53 54 78 33
             *  7 22 23 24 26 27 28 32 38 53 54 78 33
             *  7 22 23 24 26 27 28 32 33 38 53 54 78
             */

            int[]     arr_shs = { 7, 26, 53, 22, 32, 28, 38, 23, 24, 54, 27, 78, 33 };
            ShellSort shs     = new ShellSort();

            Console.WriteLine("希尔排序:");
            shs.MyShellSort(arr_shs);

            /*result
             *  gap=13
             *  本轮结果:
             *  7 26 53 22 32 28 38 23 24 54 27 78 33
             *  gap=4
             *  7 26 53 22 32 28 38 23 24 54 27 78 33
             *  7 26 53 22 32 28 38 23 24 54 27 78 33
             *  7 26 38 22 32 28 53 23 24 54 27 78 33
             *  7 26 38 22 32 28 53 23 24 54 27 78 33
             *  7 26 38 22 24 28 53 23 32 54 27 78 33
             *  7 26 38 22 24 28 53 23 32 54 27 78 33
             *  7 26 27 22 24 28 38 23 32 54 53 78 33
             *  7 26 27 22 24 28 38 23 32 54 53 78 33
             *  7 26 27 22 24 28 38 23 32 54 53 78 33
             *  本轮结果:
             *  7 26 27 22 24 28 38 23 32 54 53 78 33
             *  gap=1
             *  7 26 27 22 24 28 38 23 32 54 53 78 33
             *  7 26 27 22 24 28 38 23 32 54 53 78 33
             *  7 22 26 27 24 28 38 23 32 54 53 78 33
             *  7 22 24 26 27 28 38 23 32 54 53 78 33
             *  7 22 24 26 27 28 38 23 32 54 53 78 33
             *  7 22 24 26 27 28 38 23 32 54 53 78 33
             *  7 22 23 24 26 27 28 38 32 54 53 78 33
             *  7 22 23 24 26 27 28 32 38 54 53 78 33
             *  7 22 23 24 26 27 28 32 38 54 53 78 33
             *  7 22 23 24 26 27 28 32 38 53 54 78 33
             *  7 22 23 24 26 27 28 32 38 53 54 78 33
             *  7 22 23 24 26 27 28 32 33 38 53 54 78
             *  本轮结果:
             *  7 22 23 24 26 27 28 32 33 38 53 54 78
             */

            int[]         arr_ses = { 7, 26, 53, 22, 32, 28, 38, 23, 24, 54, 27, 78, 33 };
            SelectionSort ses     = new SelectionSort();

            Console.WriteLine("选择排序:");
            ses.MySelectionSort(arr_ses);

            /*result
             *  7 26 53 22 32 28 38 23 24 54 27 78 33
             *  7 22 53 26 32 28 38 23 24 54 27 78 33
             *  7 22 23 53 32 28 38 26 24 54 27 78 33
             *  7 22 23 24 53 32 38 28 26 54 27 78 33
             *  7 22 23 24 26 53 38 32 28 54 27 78 33
             *  7 22 23 24 26 27 53 38 32 54 28 78 33
             *  7 22 23 24 26 27 28 53 38 54 32 78 33
             *  7 22 23 24 26 27 28 32 53 54 38 78 33
             *  7 22 23 24 26 27 28 32 33 54 53 78 38
             *  7 22 23 24 26 27 28 32 33 38 54 78 53
             *  7 22 23 24 26 27 28 32 33 38 53 78 54
             *  7 22 23 24 26 27 28 32 33 38 53 54 78
             */

            int[]    arr_hs = { 7, 26, 53, 22, 32, 28, 38, 23, 24, 54, 27, 78, 33 };
            HeapSort hs     = new HeapSort();

            Console.WriteLine("堆排序:");
            hs.MyHeapSort(arr_hs);

            /*result
             *  33 54 7 24 26 53 38 23 22 32 27 28 78
             *  28 33 53 24 32 7 38 23 22 26 27 54 78
             *  27 33 28 24 32 7 38 23 22 26 53 54 78
             *  26 33 27 24 32 7 28 23 22 38 53 54 78
             *  22 26 28 24 32 7 27 23 33 38 53 54 78
             *  23 22 28 24 26 7 27 32 33 38 53 54 78
             *  27 26 23 24 22 7 28 32 33 38 53 54 78
             *  7 26 23 24 22 27 28 32 33 38 53 54 78
             *  22 7 23 24 26 27 28 32 33 38 53 54 78
             *  7 22 23 24 26 27 28 32 33 38 53 54 78
             *  7 22 23 24 26 27 28 32 33 38 53 54 78
             *  7 22 23 24 26 27 28 32 33 38 53 54 78
             */

            int[]     arr_ms = { 7, 26, 53, 22, 32, 28, 38, 23, 24, 54, 27, 78, 33 };
            MergeSort ms     = new MergeSort();

            Console.WriteLine("归并排序:");
            ms.MyMergeSort(arr_ms);

            /*result
             *  26 53
             *  7 26 53
             *  28 32
             *  22 28 32
             *  7 22 26 28 32 53
             *  23 24
             *  23 24 38
             *  27 54
             *  33 78
             *  27 33 54 78
             *  23 24 27 33 38 54 78
             *  7 22 23 24 26 27 28 32 33 38 53 54 78
             */

            int[]        arr_cs = { 7, 26, 53, 22, 32, 28, 38, 23, 24, 54, 27, 78, 33 };
            CountingSort cs     = new CountingSort();

            Console.WriteLine("计数排序1:");
            cs.MyCountingSort(arr_cs);

            /*result
             *  数组最小值:7
             *  数组最大值:78
             *  每个元素个数统计:1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 1 1 1 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
             *  每个元素值及比它值小的所有元素的个数统计:1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 4 5 6 7 7 7 7 8 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 11 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 13
             *  7 22 23 24 26 27 28 32 33 38 53 54 78
             */
            int[] arr_cs2 = { 7, 26, 53, 22, 32, 28, 38, 23, 24, 54, 27, 78, 33 };
            Console.WriteLine("计数排序2:");
            cs.MyCountingSort2(arr_cs2);

            /*result
             *  数组最小值:7
             *  数组最大值:78
             *  每个元素个数统计:0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 1 1 1 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
             *  7 22 23 24 26 27 28 32 33 38 53 54 78
             */

            int[]      arr_bus = { 7, 26, 53, 22, 32, 28, 38, 23, 24, 54, 27, 78, 33 };
            BucketSort bus     = new BucketSort();

            Console.WriteLine("桶排序:");
            bus.MyBucketSort(arr_bus);

            /*result
             *  平方根:2 5 7 4 5 5 6 4 4 7 5 8 5
             *  数组最小值:2
             *  数组最大值:8
             *  桶内元素:
             *  7 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
             *  22 23 24 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
             *  26 32 28 27 33 -1 -1 -1 -1 -1 -1 -1 -1
             *  38 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
             *  53 54 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
             *  78 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
             *  第2个桶内快排:-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 7
             *  第4个桶内快排:-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 22 23 24
             *  第5个桶内快排:-1 -1 -1 -1 -1 -1 -1 -1 26 27 28 32 33
             *  第6个桶内快排:-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 38
             *  第7个桶内快排:-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 53 54
             *  第8个桶内快排:-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 78
             *  排序结果:7 22 23 24 26 27 28 32 33 38 53 54 78
             */

            int[]     arr_rs = { 7, 26, 53, 22, 32, 28, 38, 23, 24, 54, 27, 78, 33 };
            RadixSort rs     = new RadixSort();

            Console.WriteLine("基数排序:");
            rs.MyRadixSort(arr_rs);

            /*result
             *  桶内:22 32 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
             *  53 23 33 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
             *  24 54 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
             *  26 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
             *  7 27 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
             *  28 38 78 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
             *  桶外:22 32 53 23 33 24 54 26 7 27 28 38 78
             *  桶内:7 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
             *  22 23 24 26 27 28 -1 -1 -1 -1 -1 -1 -1
             *  32 33 38 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
             *  53 54 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
             *  78 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
             *  桶外:7 22 23 24 26 27 28 32 33 38 53 54 78
             */

            Console.WriteLine("");
            Console.WriteLine("");
            int[] arr_s = { 7, 22, 23, 24, 26, 27, 28, 32, 33, 38, 53, 54, 78 };
            int   index;

            SequenceSearch ss = new SequenceSearch();

            Console.WriteLine("顺序查找:");
            index = ss.MySequenceSearch(arr_s, 53);
            Console.WriteLine("查找成功: " + index);
            index = ss.MySequenceSearch(arr_s, 52);
            Console.WriteLine("查找失败: " + index);

            /*result
             *  比较第11次
             *  查找成功: 10
             *  比较第13次
             *  查找失败: -1
             */

            BinarySearch bis = new BinarySearch();

            Console.WriteLine("二分查找1:");
            index = bis.MyBinarySearch(arr_s, 53);
            Console.WriteLine("查找成功: " + index);
            index = bis.MyBinarySearch(arr_s, 52);
            Console.WriteLine("查找失败: " + index);
            Console.WriteLine("二分查找2:");
            index = bis.MyBinarySearch2(arr_s, 53, 0, arr_s.Length - 1);
            Console.WriteLine("查找成功: " + index);
            index = bis.MyBinarySearch2(arr_s, 52, 0, arr_s.Length - 1);
            Console.WriteLine("查找失败: " + index);

            /*result
             *  low-high:7-12
             *  low-high:10-12
             *  low-high:10-10
             *  mid:10
             *  查找成功: 10
             *  low-high:7-12
             *  low-high:10-12
             *  low-high:10-10
             *  low-high:10-9
             *  查找失败: -1
             */

            InterpolationSearch ints = new InterpolationSearch();

            Console.WriteLine("插值查找1:");
            index = ints.MyInterpolationSearch(arr_s, 53);
            Console.WriteLine("查找成功: " + index);
            index = ints.MyInterpolationSearch(arr_s, 52);
            Console.WriteLine("查找失败: " + index);
            index = ints.MyInterpolationSearch2(arr_s, 53, 0, arr_s.Length - 1);
            Console.WriteLine("查找成功: " + index);
            index = ints.MyInterpolationSearch2(arr_s, 52, 0, arr_s.Length - 1);
            Console.WriteLine("查找失败: " + index);

            /*result
             *  low-high:8-12
             *  low-high:10-12
             *  mid:10
             *  查找成功: 10
             *  low-high:8-12
             *  low-high:10-12
             *  low-high:10-9
             *  查找失败: -1
             */

            FibonacciSearch fs = new FibonacciSearch();

            Console.WriteLine("斐波那契查找1:");
            index = fs.MyFibonacciSearch(arr_s, 53);
            Console.WriteLine("查找成功: " + index);
            index = fs.MyFibonacciSearch(arr_s, 52);
            Console.WriteLine("查找失败: " + index);
            Console.WriteLine("斐波那契查找2:");
            index = fs.MyFibonacciSearch2(arr_s, 53);
            Console.WriteLine("查找成功: " + index);
            index = fs.MyFibonacciSearch(arr_s, 52);
            Console.WriteLine("查找失败: " + index);

            /*result
             *  斐波那契数列:0 1 1 2 3 5 8 13 21
             *  扩展后的数组:7 22 23 24 26 27 28 32 33 38 53 54 78 78 78 78 78 78 78 78
             *  low-high-k:0-11-7
             *  low-high-k:8-11-5
             *  mid-k:10-5
             *  查找成功: 10
             *  斐波那契数列:0 1 1 2 3 5 8 13 21
             *  扩展后的数组:7 22 23 24 26 27 28 32 33 38 53 54 78 78 78 78 78 78 78 78
             *  low-high-k:0-11-7
             *  low-high-k:8-11-5
             *  low-high-k:8-9-4
             *  low-high-k:10-9-2
             *  查找失败: -1
             */

            BlockSearch bls = new BlockSearch();

            Console.WriteLine("分块查找:");
            index = bls.MyBlockSearch(arr_s, 53, 4);
            Console.WriteLine("查找成功: " + index);
            index = bls.MyBlockSearch(arr_s, 52, 4);
            Console.WriteLine("查找失败: " + index);

            /*result
             *  序列数组:
             *  7 22 23 24
             *  26 27 28 32
             *  33 38 53 54
             *  78
             *  最小值最大值:
             *  7 26 33 78 24 32 54 78
             *  low-high:2-3
             *  mid:2
             *  查找成功: 10
             *
             *  序列数组:
             *  7 22 23 24
             *  26 27 28 32
             *  33 38 53 54
             *  78
             *  最小值最大值:
             *  7 26 33 78 24 32 54 78
             *  low-high:2-3
             *  low-high:2-1
             *  查找失败: -1
             */

            int[]            arr_bts = { 32, 24, 54, 22, 27, 38, 78, 7, 23, 26, 28, 33, 53 };
            BinaryTreeSearch bts     = new BinaryTreeSearch();

            Console.WriteLine("二叉树查找1:");
            index = bts.MyBinaryTreeSearch(arr_bts, 53);
            Console.WriteLine("查找成功: " + index);
            index = bts.MyBinaryTreeSearch(arr_bts, 52);
            Console.WriteLine("查找失败: " + index);
            Console.WriteLine("二叉树查找2:");
            index = bts.MyBinaryTreeSearch2(arr_bts, 53, 0, 0);
            Console.WriteLine("查找成功: " + index);
            index = bts.MyBinaryTreeSearch2(arr_bts, 52, 0, 0);
            Console.WriteLine("查找失败: " + index);

            /*result
             *  第1次比较:i-0 arr[i]-32
             *  第2次比较:i-2 arr[i]-54
             *  第3次比较:i-5 arr[i]-38
             *  第4次比较:i-12 arr[i]-53
             *  查找成功: 12
             *  第1次比较:i-0 arr[i]-32
             *  第2次比较:i-2 arr[i]-54
             *  第3次比较:i-5 arr[i]-38
             *  第4次比较:i-12 arr[i]-53
             *  查找失败: -1
             */

            Console.ReadKey();
        }