Skip to content

Commit 4612ae7

Browse files
Merge pull request #715 from bohemian997/master
Added "Linear Search Algorithm" in Golang in Go Directory
2 parents 6426750 + acb9b11 commit 4612ae7

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Go/linear_search.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package search
2+
3+
// LinearSearch returns the index of the given key found on the list.
4+
// It returns a value of -1 if the key doesn't exist
5+
func LinearSearch(list []int, key int) int {
6+
for index, element := range list {
7+
if key == element {
8+
return index
9+
}
10+
}
11+
12+
return -1
13+
}

0 commit comments

Comments
 (0)