Linear Simple linear search algorithm that iterates over all elements of an array in the worst case scenario
(array []int, query int)
| 2 | |
| 3 | // Linear Simple linear search algorithm that iterates over all elements of an array in the worst case scenario |
| 4 | func Linear(array []int, query int) (int, error) { |
| 5 | for i, item := range array { |
| 6 | if item == query { |
| 7 | return i, nil |
| 8 | } |
| 9 | } |
| 10 | return -1, ErrNotFound |
| 11 | } |
no outgoing calls