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.16 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.15 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.14 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.13 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.12 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.11 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.10 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.9 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.8 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.7 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.6 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.5 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.4 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.3 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.2 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.1 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.1.0 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.0.6 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.0.5 tracks/go/exercises/binary-search-tree/example.go
trackler-2.2.0.4 tracks/go/exercises/binary-search-tree/example.go