Created
February 27, 2012 06:06
-
-
Save dmjio/1921826 to your computer and use it in GitHub Desktop.
LinearSearch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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