Commits

Anonymous committed ab8e167

adding search items

  • Participants
  • Parent commits 43cc047

Comments (0)

Files changed (3)

File searching/Makefile

+
+include $(GOROOT)/src/Make.inc
+
+TARG=algos/search
+
+GOFILES=\
+	sequential_search.go\
+
+
+include $(GOROOT)/src/Make.pkg

File searching/search_test.go

+// Copyright 2009 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package search
+
+import (
+	"testing"
+)
+
+
+func TestSequentialSearch(t *testing.T) {
+	array := []int{1, 4, 8, 9, 11, 15, 17, 22, 23, 26}
+	s := SequentialSearch(array, 15)
+	if !s {
+		t.Fail()
+	}
+}
+
+

File searching/sequential_search.go

+/*
+
+*/
+package search
+
+
+func SequentialSearch(array []int, t int) bool {
+	for i := len(array)-1; i >= 1; i-- {
+		if array[i] == t {
+			return true
+		}
+	}
+	return false
+}