March 2019
Intermediate to advanced
336 pages
9h 9m
English
The InsertElement method inserts the element with the given key and value in the binary search tree. The tree's lock() instance is locked first and the unlock() method is deferred before inserting the element. The InsertTreeNode method is invoked by passing rootNode and the node to be created with the key and value, as shown here:
// InsertElement methodfunc (tree *BinarySearchTree) InsertElement(key int, value int) { tree.lock.Lock() defer tree.lock.Unlock() var treeNode *TreeNode treeNode= &TreeNode{key, value, nil, nil} if tree.rootNode == nil { tree.rootNode = treeNode } else { insertTreeNode(tree.rootNode, treeNode) }}
The example output for inserting an element with key and value 3 is shown as follows. The ...
Read now
Unlock full access