Skip to content

Instantly share code, notes, and snippets.

@dmjio
Created Feb 27, 2012
Embed
What would you like to do?
LinearSearch
public int LinearSearch(int[] arr, int x)
{
int i = 0;
int location = 0;
int n = arr.Length -1;
while (i < n && arr[i] != x)
{
i++;
}
if (i < n)
location = i;
else
location = 0;
return location;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment