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.
A possible approach (which I took) is to treat the entire tree as one big data structure, with a collection of nodes, and various representations of the links between them (i.e. think Graph represented as an adjancy list). You can then expose a trait called Tree, which is in fact just a front for the tree and a specific node in it (i.e. the tree and a node id). Each operation on the node is performed "behind the scenes" as an operation on the entire tree, and then return a new Tree and node. Then again I supposed that's just another way of describing the zipper principle, just implemented in an object-oriented way.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Tree manager
You are viewing a single comment's thread. Return to all comments →
A possible approach (which I took) is to treat the entire tree as one big data structure, with a collection of nodes, and various representations of the links between them (i.e. think Graph represented as an adjancy list). You can then expose a trait called Tree, which is in fact just a front for the tree and a specific node in it (i.e. the tree and a node id). Each operation on the node is performed "behind the scenes" as an operation on the entire tree, and then return a new Tree and node. Then again I supposed that's just another way of describing the zipper principle, just implemented in an object-oriented way.