Skip to content

Instantly share code, notes, and snippets.

@dmjio
Created February 27, 2012 06:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmjio/1921826 to your computer and use it in GitHub Desktop.
Save dmjio/1921826 to your computer and use it in GitHub Desktop.
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