Exemplo n.º 1
0
        static void Main(string[] args)
        {
            int size;

            Console.WriteLine("Enter size of your array");
            size = int.Parse(Console.ReadLine());
            int key;
            int result;

            BinarySearchClass BSobj = new BinarySearchClass(size);

            Console.WriteLine("\nEnter your desired number  to Search its FIRST OCCURRENCE : ");
            key    = int.Parse(Console.ReadLine());
            result = BSobj.BSFirstOCC(key);
            if (result != -1)
            {
                Console.WriteLine("Your desired element's first occurrence found at index " + result + " in given array..");
            }
            else
            {
                Console.WriteLine("Element not found in array");
            }


            Console.WriteLine("Enter your desired number to Search its last OCCURRNCE : ");
            key    = int.Parse(Console.ReadLine());
            result = BSobj.BSLastOCC(key);
            if (result != -1)
            {
                Console.WriteLine("Your desired element's last occurrence found at index " + result + " in given array..");
            }
            else
            {
                Console.WriteLine("Element not found in array");
            }

            Console.WriteLine("Enter your desired number count to Search its COUNT : ");
            key    = int.Parse(Console.ReadLine());
            result = BSobj.BSCount(key);
            if (result != -1)
            {
                Console.WriteLine("Your desired element's total occurrence found are " + result + " in given array..");
            }
            else
            {
                Console.WriteLine("Element not found in array");
            }



            Console.Read();
        }
Exemplo n.º 2
0
 public static void Main(string[] args)
 {
     Console.WriteLine(BinarySearchClass.Search(BinarySearchClass.MyArray).ToString());
 }