Return an Enumerator When Your Collection Has Multiple Traversals
16-Aug-2024 394
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.
Return an Enumerator When Your Collection Has Multiple Traversals #ruby #rubydeveloper #rubyonrails #Return #Enumerator #Collection #Multiple #Traversals https://rubyonrails.ba/link/return-an-enumerator-when-your-collection-has-multiple-traversals