Beispiel #1
0
        static void Main(string[] args)
        {
            LinearSearch aLinearSearch = new LinearSearch();

            var result = aLinearSearch.Linear_Search(new[] { 1, 2, 3, 4, 5 }, 5, 4);

            Console.WriteLine(result);
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            int size;

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

            LinearSearch LSobj = new LinearSearch(size);

            Console.WriteLine("\nEnter your desired number  to Search its FIRST OCCURENCE : ");
            key    = int.Parse(Console.ReadLine());
            result = LSobj.LinearSearchFirstOCC(key);
            if (result != -1)
            {
                Console.WriteLine("Your desired element's first occurence 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 OCCURNCE : ");
            key = int.Parse(Console.ReadLine());

            result = LSobj.LinearSearchLastOCC(key);
            if (result != -1)
            {
                Console.WriteLine("Your desired element's last occurence 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 = LSobj.LinearSearchCount(key);
            if (result != -1)
            {
                Console.WriteLine("Your desired element's total occurrence found are " + result + " in given array..");
            }
            else
            {
                Console.WriteLine("Element not found any occurrence in array");
            }



            Console.Read();
        }