namespace BinaryTreeIteratorUsingGenerator { class BinaryTreeNode < T > { value : T ; left : BinaryTreeNode < T > | undefined ; right : BinaryTreeNode < T > | undefined ; constructor ( value ) { this . value = value ; } } function * inOrderIterator < T > ( root ) { if ( root . left ) { for ( const value of inOrderIterator ( root . left ) ) { yield value ; } } yield root . value ; if ( root . right ) { for ( const value of inOrderIterator ( root . right ) ) { yield value ; } } } }