Created
April 3, 2018 05:37
-
-
Save RavenZZ/ee5bed037f6bf2c54b5168650728be39 to your computer and use it in GitHub Desktop.
This technique pass over the list of elements, by using the index to move from the beginning of the list to the end. Each element is examined and if it does not match the search item, the next item is examined. By hopping from one item to its next, t
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Linear Search in Golang | |
package main | |
import "fmt" | |
func linearsearch(datalist []int, key int) bool { | |
for _, item := range datalist { | |
if item == key { | |
return true | |
} | |
} | |
return false | |
} | |
func main() { | |
items := []int{95,78,46,58,45,86,99,251,320} | |
fmt.Println(linearsearch(items,58)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment