Skip to content

Instantly share code, notes, and snippets.

@igavrysh
Created July 16, 2021 16:47
Show Gist options
  • Save igavrysh/bef2183faab68e75187c44b13622c9fe to your computer and use it in GitHub Desktop.
Save igavrysh/bef2183faab68e75187c44b13622c9fe to your computer and use it in GitHub Desktop.
package main
import "sync"
type BinaryTreeData interface {
Less(element BinaryTreeData) bool
}
type BinaryTreeNode struct {
Data BinaryTreeData
Left *BinaryTreeNode
Right *BinaryTreeNode
}
type BinaryTree struct {
root *BinaryTreeNode
lock sync.RWMutex
}
func NewBinaryTree() *BinaryTree {
return &BinaryTree{}
}
func (bt *BinaryTree) Insert(data BinaryTreeData) {
bt.lock.Lock()
defer bt.lock.Unlock()
n := &BinaryTreeNode{data, nil, nil}
if bt.root == nil {
bt.root = n
} else {
insertNode(bt.root, n)
}
}
func insertNode(node *BinaryTreeNode, newNode *BinaryTreeNode) {
if newNode.Data.Less(node.Data) {
}
}
func (bt *BinaryTree) Traversal() BinaryTreeData {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment