Problem statement: what do you mean by Preorder traversal in tree?
- Preorder traversal is defined as follows:
- visit the root
- traverse the left subtree in preorder
- traverse the right subtree in preorder
- Recursive Preorder Traversal:
- void PreOrder(BinaryTreeNode root){
- if(root !=null){
- System.out.println(root.getData());
- PreOrder(root.getLeft());
- PreOrder(root.getRight());
- }
- }
No comments:
Post a Comment