MCPcopy Create free account
hub / github.com/0xAX/go-algorithms / insert

Function insert

sorting/treesort.go:23–33  ·  view source on GitHub ↗

insert nodes into a binary search tree

(root *node, val int)

Source from the content-addressed store, hash-verified

21
22// insert nodes into a binary search tree
23func insert(root *node, val int) *node {
24 if root == nil {
25 return newNode(val)
26 }
27 if val < root.val {
28 root.left = insert(root.left, val)
29 } else {
30 root.right = insert(root.right, val)
31 }
32 return root
33}
34
35// inorder traversal algorithm
36// Copies the elements of the bst to the array in sorted order

Callers 1

treesortFunction · 0.85

Calls 1

newNodeFunction · 0.85

Tested by

no test coverage detected