Tree Preorder Traversal using Java
/*
Node is defined as
class Node {
int data;
Node left;
Node right;
}
*/
- void Preorder(Node root) {
- System.out.print(root.data + " ");
- if (root.left != null) {
- Preorder(root.left);
- }
-
- if (root.right != null) {
- Preorder(root.right);
- }
- }
No comments:
Post a Comment