Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
timedLinearSearch
public static void findStudent(int key, int[] studentList) {
final long startTime = System.nanoTime();
int N = studentList.length;
for(int i = 0; i < N; i++) {
if(studentList[i] == key) {
System.out.println("Key has been found");
} else System.out.println(" Key was not found ");
}
final long endTime = System.nanoTime();
System.out.println("Total execution time: " + (endTime - startTime) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment