Golang program for implementation of Linear Search
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, the list is passed over sequentially.
Example
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))
}
Output
true
Most Helpful This Week
Golang program for implementation of Tower of Hanoi Algorithm
Golang program for implementation of Quick Sort
Golang program for implementation of Floyd–Warshall Algorithm
Golang program to print a matrix in Spiral Format
Golang program for implementation of Shell Sort
Golang program for implementation of Bubble Sort
Golang program for implementation of Longest Common Sub-sequence
Golang program for implementation of Interpolation Search
Golang program to generate number of slices permutations of number entered by user
Golang program for implementation of Median of Medians