Skip to content

Instantly share code, notes, and snippets.

@nitschmann
Created October 14, 2012 20:55
Show Gist options
  • Save nitschmann/3889796 to your computer and use it in GitHub Desktop.
Save nitschmann/3889796 to your computer and use it in GitHub Desktop.
Java method for linearly search
static int linearlySearch(int[] field, int searchIndex) {
for (int i = 0; i < field.length; i++)
if (field[i] == searchIndex)
return i;
return -1; // -1 no valid index
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment