Milo Chang
Avanish Gupta
Milo Chang
Avanish Gupta
ArrayList Implementation
public static int linearSearch(ArrayList<Integer> array, int n) {
for (int i = 0; i < array.size(); i++) {
if (array.get(i) == n) {
return i;
}
}
return -1;
}
Integer Array Implementation
public static int linearSearch(int[] array, int n) {
for (int i = 0; i < array.length; i++) {
if (array[i] == n) {
return i;
}
}
return -1;
}
© 2024 Fiveable Inc. All rights reserved.