Loading…
Loading…
Checks each element in turn until the target is found or the array ends. Works on any array, sorted or not.
Scan left to right for 53.
Tip: click any bar to make it the target.
1int linearSearch(int[] a, int target) {2 for (int i = 0; i < a.length; i++)3 if (a[i] == target) return i;4 return -1;5}