Friday, 16 December 2016

Sequential Search in C#

Input -
1. one Array
2. one value to be searched

Algorithm
I am giving one simple example.

bool SequenceSearch(int[] arr, int svalue)
        {

            for (int index = 0; index < arr.Length - 1; index++)
            {
                if (arr[index] == svalue)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            return false;

        }

If 'svalue' is found in array then it will return true otherwise false.

No comments:

Post a Comment