Added Linear Search function in Java8 (#19214)

pull/19195/merge
Devansh Upadhyay 2018-10-16 09:44:59 +05:30 committed by Quincy Larson
parent fac8e975dd
commit 897535e4a0
1 changed files with 14 additions and 0 deletions

View File

@ -104,6 +104,20 @@ func linearSearch(for number: Int, in array: [Int]) -> Int? {
return nil // the number was not found in the array
}
```
### Example in Java
```Java 8
int linearSearch(int[] arr, int element)
{
for(int i=0;i<arr.length;i++)
{
if(arr[i] == element)
return i;
}
return -1;
}
```
## Global Linear Search