forked from jsquared21/Intro-to-Java-Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise_19_04.java
More file actions
17 lines (17 loc) · 778 Bytes
/
Exercise_19_04.java
File metadata and controls
17 lines (17 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/************************************************************************************
* (Generic linear search) Implement the following generic method for linear search. *
* *
* public static <E extends Comparable<E>> *
* int linearSearch(E[] list, E key) *
************************************************************************************/
public class Exercise_19_04 {
/** Method finds the key in a list */
public static <E extends Comparable<E>>
int linearSearch(E[] list, E key) {
for (int i = 0; i < list.length; i++) {
if (key.compareTo(list[i]) == 0)
return i;
}
return -1;
}
}