Return an Enumerator When Your Collection Has Multiple Traversals

16-Aug-2024 329
Unlike an array where usually there’s only a single way you’d want to traverse it, binary trees have many common ways of being traversed. Let’s say you’re building a binary tree object and you want to support the 3 classic depth-first traversals:Pre-order - evaluate a node itself first, then its left subtree, then its right subtreeIn-order evaluate the left subtree, then the node itself, then the right subtreePost-order evaluate the left subtree, then the right subtree, then finally the node itself.
Use coupon code:

RUBYONRAILS

to get 30% discount on our bundle!
Prepare for your next tech interview with our comprehensive collection of programming interview guides. Covering JavaScript, Ruby on Rails, React, and Python, these highly-rated books offer thousands of essential questions and answers to boost your interview success. Buy our 'Ultimate Job Interview Preparation eBook Bundle' featuring 2200+ questions across multiple languages. Ultimate Job Interview Preparation eBook Bundle