February 2014
Beginner
1248 pages
62h 25m
English
Method linearSearch (lines 10–18) performs the linear search. The method receives as parameters the array to search (data) and the searchKey. Lines 13–15 loop through the elements in the array data. Line 14 compares each with searchKey. If the values are equal, line 15 returns the index of the element. If there are duplicate values in the array, linear search returns the index of the first element in the array that matches the search key. If the loop ends without finding the value, line 17 returns -1.
Read now
Unlock full access