Exemplo n.º 1
0
        static void Main()
        {
            Console.WriteLine("\nEnter numbers to fill list (press enter to stop):\n");
            var inputList = ListCreator.CreateList();

            inputList = BinarySearcher.SortList(inputList);
            Console.WriteLine("\nEnter number to seach\n");
            var numberToSearch = IOHelper.ParseInput();
            var result         = BinarySearcher.BinarySearch(inputList, numberToSearch);

            if (result > 0)
            {
                Console.WriteLine("Element found " + result);
            }
            else
            {
                Console.WriteLine("Element not found");
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("BinarySearch");

            BinarySearcher search = new BinarySearcher();

            int[] test = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            int find   = -1;
            int result = search.BinarySearch(test, find);

            if (result == -1)
            {
                Console.WriteLine($"{find} is not in the array");
            }
            else
            {
                Console.WriteLine($"index of:{find} is {result}");
            }
            Console.Read();
        }