fork download
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. type array []int
  6.  
  7. func (arr array) linearSearch(number int) bool {
  8. for i := 0; i < len(arr); i++ {
  9. if arr[i] == number {
  10. return true
  11. }
  12. }
  13.  
  14. return false
  15. }
  16.  
  17. func main() {
  18. arr := array{8, 2, 9, 10, 5, 4, 2, 7, 18, 0}
  19. number := 7
  20.  
  21. result := arr.linearSearch(number)
  22.  
  23. if result {
  24. fmt.Println("Liczba jest w tablicy")
  25. } else {
  26. fmt.Println("Liczby nie ma w tablicy")
  27. }
  28. }
Success #stdin #stdout 0.01s 7380KB
stdin
Standard input is empty
stdout
Liczba jest w tablicy