Beispiel #1
0
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var key   = int.Parse(Console.ReadLine());

            if (input == string.Empty)
            {
                return;
            }

            var arr = input
                      .Split()
                      .Select(int.Parse)
                      .ToArray();

            var index = BinarySearch.IndexOf(arr, key);

            Console.WriteLine(index);
        }
        static void Main(string[] args)
        {
            int key = 9;

            decimal []   numbers       = new decimal[10];
            decimal[]    numbersSorted = new decimal[10];
            Random       objR          = new Random();
            BinarySearch objBS         = new BinarySearch();

            for (int i = 0; i < numbers.Length; i++)
            {
                numbers[i] = objR.Next(1, 15);
            }

            numbersSorted = numbers.ToArray().OrderBy(x => x).ToArray();

            Console.WriteLine(objBS.ComputeBinarySearch(key, numbersSorted, 0, numbersSorted.Length - 1));
            Console.WriteLine(objBS.ComputeBinarySearchIterative(key, numbersSorted, 0, numbersSorted.Length - 1));
            Console.ReadLine();
        }