Tree Preorder Traversal using Java



/*
Node is defined as

class Node {
    int data;
    Node left;
    Node right;
}
*/




  1. void Preorder(Node root) {
  2. System.out.print(root.data + " ");

  3.     if (root.left != null) {
  4.         Preorder(root.left);
  5.     } 
  6.     
  7.     if (root.right != null) {
  8.         Preorder(root.right);
  9.     }
  10. }

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Hibernate Search - Elasticsearch with JSON manipulation

Spring Elasticsearch Operations