Created
July 16, 2021 16:47
-
-
Save igavrysh/bef2183faab68e75187c44b13622c9fe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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