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.
Tree: Preorder Traversal
Tree: Preorder Traversal
Sort by
recency
|
444 Discussions
|
Please Login in order to post a comment
JavaScript solution using recursion
Haskell
It would have been nice if the problem statement gave an actual sample of the expected input data and how to parse it... Bad form, folks.
class Node: def init(self,val): self.value=val self.left=None self.right=None
class Tree: def init(self): self.root=None
n=int(input()) nums=list(map(int,input().split())) tree=Tree() tree.root=Node(nums[0]) for num in nums[1:]: tree.insert(tree.root,num) tree.preOrder(tree.root)
There is a gotcha here, that the C# template doesn't parse the input like the languages. And the description doesn't describe how to parse the input.