Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Pseudocode:

1. Define a Node class representing a node in the binary search tree. Each node has an
integer data value, and pointers to its left and right child nodes.
2. Define BST class representing the binary search tree. It has a private member variable
root that points to the root node of the tree.
3. Create insertRecursive function as a private recursive helper function of the BST class. It
takes a currentNode and a value as parameters and inserts a new node with the given
value into the BST. If the currentNode is nullptr, meaning we have reached the
appropriate position in the tree to insert the new value, a new node is created with the
given value and returned. If the value is less than the currentNode's data, the function
recursively calls insertRecursive on the left child of the currentNode. If the value is
greater than the currentNode's data, the function recursively calls insertRecursive on
the right child of the currentNode.
4. Create searchRecursive function which takes a currentNode and a value as parameters
and searches for the value in the BST. If the currentNode is nullptr, the value is not
found, so it returns false. If the value is equal to the currentNode's data, the value is
found, so it returns true. If the value is less than the currentNode's data, the function
recursively calls searchRecursive on the left child of the currentNode. If the value is
greater than the currentNode's data, the function recursively calls searchRecursive on
the right child of the currentNode.
5. Create inorderTraversalRecursive function which performs an in-order traversal of the
BST, visiting nodes in ascending order. If the currentNode is not nullptr, it recursively
calls inorderTraversalRecursive on the left child of the currentNode, prints the
currentNode's data, and then recursively calls inorderTraversalRecursive on the right
child of the currentNode.
6. Create insert function for value into the BST. It calls the insertRecursive function with
the root and the value as parameters. The search method of the BST class allows
searching for a value in the BST. It calls the searchRecursive function with the root and
the value as parameters.
7. Create inorderTraversal function which calls the inorderTraversalRecursive function with
the root as a parameter and then prints a newline character.

You might also like