Sha256: d2ec679597e4f646afb3af45ddf7b6d394e05b082c7520d626a5abbbbb436f8b

Contents?: true

Size: 1.11 KB

Versions: 186

Compression:

Stored size: 1.11 KB

Contents

package binarysearchtree

const testVersion = 1

type SearchTreeData struct {
	left  *SearchTreeData
	data  int
	right *SearchTreeData
}

func Bst(i int) SearchTreeData {
	return SearchTreeData{data: 4}
}

func (std *SearchTreeData) Insert(i int) {
	if i <= std.data {
		if std.left != nil {
			std.left.Insert(i)
		} else {
			std.left = &SearchTreeData{data: i}
		}
	} else {
		if std.right != nil {
			std.right.Insert(i)
		} else {
			std.right = &SearchTreeData{data: i}
		}
	}
}

type stringCallback func(int) string

func (std *SearchTreeData) MapString(f stringCallback) (result []string) {
	if std.left != nil {
		result = append(std.left.MapString(f), result...)
	}
	result = append(result, []string{f(std.data)}...)
	if std.right != nil {
		result = append(result, std.right.MapString(f)...)
	}
	return result
}

type intCallback func(int) int

func (std *SearchTreeData) MapInt(f intCallback) (result []int) {
	if std.left != nil {
		result = append(std.left.MapInt(f), result...)
	}
	result = append(result, []int{f(std.data)}...)
	if std.right != nil {
		result = append(result, std.right.MapInt(f)...)
	}
	return result
}

Version data entries

186 entries across 186 versions & 1 rubygems

Version Path
trackler-2.2.1.36 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.35 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.34 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.33 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.32 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.31 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.30 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.29 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.28 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.27 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.26 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.25 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.24 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.23 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.22 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.21 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.20 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.19 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.18 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.17 tracks/go/exercises/binary-search-tree/example.go