Last active
August 6, 2020 16:08
-
-
Save LeoPFreitas/2c57f351c229e6e8ebda4a1460ff3583 to your computer and use it in GitHub Desktop.
Linear search in array of integers.
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 static int linearSearchArray(int[] array, int value) { | |
int index = -1; | |
for (int i = 0; i < array.length; i++) { | |
if (array[i] == value) { | |
index = i; | |
break; | |
} | |
} | |
return index; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment