Beispiel #1
0
        static void Main(string[] args)
        {
            int    key, size, result;
            string parameters;

            Console.WriteLine("Binary Search");
            Console.WriteLine("Type - size:key");
            parameters = Console.ReadLine();

            size = Int32.Parse(parameters.Split(':')[0]);
            key  = Int32.Parse(parameters.Split(':')[1]);

            result = BinarySearch.Search(GenerateArray(size), key);

            if (result != -1)
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("{1} found at {0} position.", result, key);
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("{0} not found.", key);
            }
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Welcome to  Binary Search.");
            Console.WriteLine();

            Console.WriteLine("Input sorted array please.");
            Console.WriteLine();

            int[] sortedArry = new int[10];
            for (int i = 0; i < sortedArry.Length; i++)
            {
                sortedArry[i] = int.Parse(Console.ReadLine());
            }

            Console.WriteLine("Please input the key.");
            Console.WriteLine();

            int key = int.Parse(Console.ReadLine());

            if (BinarySearch.Search(sortedArry, key))
            {
                Console.WriteLine("Key with value : {0} is found in the array.", key.ToString());
            }

            else
            {
                Console.WriteLine("Key with value : {0} is not found in the array,", key.ToString());
            }

            Console.ReadKey();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            int[] x = GetArrayAsInput();
            int   y = ElementToFindInArray();

            BinarySearch srch = new BinarySearch();

            srch.Search(x, y);
        }