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.56 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.55 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.54 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.53 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.52 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.51 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.50 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.49 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.48 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.47 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.46 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.45 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.44 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.43 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.42 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.41 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.40 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.39 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.38 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.37 tracks/go/exercises/binary-search-tree/example.go