コード例 #1
0
        private static void LinearSearchTest(int[] arr, int valueToFind)
        {
            bool found = false;

            Console.WriteLine("Linear Search Test");

            ISearchable linearSearch = new LinearSearch();

            linearSearch.StartTimer();

            found = linearSearch.Search(arr, valueToFind);

            linearSearch.StopTimer();

            //Console.WriteLine($"Found value {valueToFind} : {found} ");

            if (_printArray)
            {
                linearSearch.PrintArray(arr);
            }

            linearSearch.PrintElapsedTime();

            linearSearch.ResetTimer();
        }
コード例 #2
0
        private static void ExecuteLinearSearch()
        {
            var array = new int[] { 7, 2, 7, 9, 1, 3, 3 };
            var item  = 7;

            Console.WriteLine($"Array - {string.Join(",", array)}");
            Console.WriteLine($"Linear Search - {item}");
            var algo  = new LinearSearch();
            var index = algo.Search(array, item);

            Console.WriteLine($"Item {item} present at index- {index}");
        }
コード例 #3
0
        static void Main(string[] args)
        {
            int[] arr = { 1, 10, 30, 15, 23, 44, 62, 1, 4, 8, 6, -6 };
            int   x   = 30;

            Console.WriteLine("Given Number : " + x);


            //LINEAR SEARCH
            Console.WriteLine("Linear Search Algorithm Result : " + LinearSearch.search(arr, x) + " are greater than " + x);


            //BINARY SEARCH
            Console.WriteLine("Binary Search Algorithm Result : " + BinarySearch.binarySearch(arr.OrderBy(y => y).ToArray(), 0, arr.Length - 1, x) + " are greater than " + x);


            Console.Read();
        }
コード例 #4
0
        static void Main(string[] args)
        {
            //double answer = 7.0 / 2.0;

            //int remainder = 7 % 2;
            //level level
            var isPaliPhrase = PalidromeEquality.IsPalindromePhrase("Red rum, sir, is murder");
            var isPalinWord  = PalidromeEquality.IsPalindrome("isLevel");
            int quotient     = 7 / 2;

            //HanoiTower.Move(5, "A", "C", "B");
            int [] array  = new int[] { 1, 2, 3, 5, 7, 9 };
            var    linear = new LinearSearch();
            var    result = linear.BinarySearch(array, 11);

            Console.Write(result);
            Console.ReadKey();
        }