Skip to content

Instantly share code, notes, and snippets.

@ssaurel
Last active April 9, 2019 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssaurel/161821ce171cb79f2d2ff4403c5e1ccd to your computer and use it in GitHub Desktop.
Save ssaurel/161821ce171cb79f2d2ff4403c5e1ccd to your computer and use it in GitHub Desktop.
Tree Building for the Tree Traversal Algorithms in Java on the SSaurel's Channel
public class Tree {
public static void main(String[] args) {
// We create the nodes of our tree
Node<String> A = new Node<String>("A");
Node<String> B = new Node<String>("B");
Node<String> C = new Node<String>("C");
Node<String> D = new Node<String>("D");
Node<String> E = new Node<String>("E");
Node<String> F = new Node<String>("F");
Node<String> G = new Node<String>("G");
Node<String> H = new Node<String>("H");
Node<String> I = new Node<String>("I");
Node<String> J = new Node<String>("J");
Node<String> K = new Node<String>("K");
// Root and building of the tree
Node<String> root = A;
A.left = B; A.right = C;
B.left = D; B.right = E;
D.left = H; D.right = I;
E.left = J;
C.left = F; C.right = G;
G.left = K;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment