We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Here is my solution with recursion. The key is checking if the root exists, and if it does you check if data is greater than or less than the root's data. If greater call the function with the right child and data. If it is less than call the function with the left child and data. Otherwise the correct leaf has been reached and the data will be added to a new Node and appended to the left if less than or right if greater than.
Binary Search Tree : Insertion
You are viewing a single comment's thread. Return to all comments →
Here is my solution with recursion. The key is checking if the root exists, and if it does you check if data is greater than or less than the root's data. If greater call the function with the right child and data. If it is less than call the function with the left child and data. Otherwise the correct leaf has been reached and the data will be added to a new Node and appended to the left if less than or right if greater than.