Skip to content

Commit 2dc1af2

Browse files
jpoirierjpoirier
authored andcommitted
adding search items
1 parent f4b3350 commit 2dc1af2

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

searching/Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
include $(GOROOT)/src/Make.inc
3+
4+
TARG=algos/search
5+
6+
GOFILES=\
7+
sequential_search.go\
8+
9+
10+
include $(GOROOT)/src/Make.pkg

searching/search_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2009 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package search
6+
7+
import (
8+
"testing"
9+
)
10+
11+
12+
func TestSequentialSearch(t *testing.T) {
13+
array := []int{1, 4, 8, 9, 11, 15, 17, 22, 23, 26}
14+
s := SequentialSearch(array, 15)
15+
if !s {
16+
t.Fail()
17+
}
18+
}
19+
20+

searching/sequential_search.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
3+
*/
4+
package search
5+
6+
7+
func SequentialSearch(array []int, t int) bool {
8+
for i := len(array)-1; i >= 1; i-- {
9+
if array[i] == t {
10+
return true
11+
}
12+
}
13+
return false
14+
}

0 commit comments

Comments
 (0)