I need pseudo code for a function that will insert an item into a binary search tree. the insert function will take a parameter of the item to insert and will call a recursive helper function to actually add the item which will have the parameters (pointer to root of tree, item to insert). Each node has a value, and a left and right child pointer.
Expert Answer
Insert(Node root, Key k)
if (root == null) // insert at this node
return new Node(k);
if (k <= root.key) // proceed to the left branch
root.left = Insert(root.left, k);
else // k > root.key, i.e. proceed to the right branch
root.right = Insert(root.right, k);
return root;
Don't use plagiarized sources. Get Your Custom Essay on
Question & Answer: I need pseudo code for a function that will insert an item into a binary search tree. the insert function will take a…..
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS $13/PAGE