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: Inorder Traversal
Tree: Inorder Traversal
Sort by
recency
|
208 Discussions
|
Please Login in order to post a comment
Haskell
Performs an in-order traversal of a binary tree.
class Node: def init(self, val): self.value = val self.right = None self.left = None
class Tree: def init(self): self.root = None
n=int(input()) numbers = list(map(int,input().split()))
Initialize the tree and create roottree = Tree() tree.root = Node(numbers[0])
Insert remaining numbersfor number in numbers[1:]: tree.insert(tree.root, number)
Perform in-order traversal
tree.inorder(tree.root)
for C# language the input should be read from stdin, but how to construct a tree from it? Typically you construct a binary tree from array using rules: The left child of the node at index i is at index 2*i + 1. The right child of the node at index i is at index 2*i + 2