DIY: Binary Search Tree Iterator
Understand how to implement a binary search tree iterator type that supports in-order traversal using Next and HasNext methods. Learn to handle traversal logic to retrieve nodes in ascending order and manage iteration state. This lesson helps you build a reusable iterator to process BST elements one at a time, crucial for coding interviews involving tree traversal.
We'll cover the following...
We'll cover the following...
Problem statement
In this challenge, you have to implement a binary search tree iterator type called BSTIterator. The iterator will be initialized by the root node of the BST. You have to implement two methods:
Next(): This will return the next smallest number in the BST.