diff --git a/src/pkg1/Aryansh_Class.class b/src/pkg1/Aryansh_Class.class new file mode 100644 index 0000000..7b23fe1 Binary files /dev/null and b/src/pkg1/Aryansh_Class.class differ diff --git a/src/pkg1/Aryansh_Class.java b/src/pkg1/Aryansh_Class.java new file mode 100644 index 0000000..a56a8b1 --- /dev/null +++ b/src/pkg1/Aryansh_Class.java @@ -0,0 +1,46 @@ +package pkg1; +public class Aryansh_Class { + public TreeNode root; + + public class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int val){ + this.val = val; + } + } + + public void createBinaryTree(){ + TreeNode first = new TreeNode(9); + TreeNode second = new TreeNode(2); + TreeNode third = new TreeNode(4); + TreeNode fourth = new TreeNode(8); + TreeNode fifth = new TreeNode(1); + TreeNode sixth = new TreeNode(6); + TreeNode seventh = new TreeNode(7); + + root = first; + first.left = second; + first.right = third; + + second.left = fourth; + second.right = fifth; + + third.left = sixth; + third.right = seventh; + + } + + public void preorder(TreeNode root){ + if(root == null) + return; + + System.out.print(root.val + " "); + preorder(root.left); + preorder(root.right); + } + + +} \ No newline at end of file diff --git a/src/pkg1/MasterClass.java b/src/pkg1/MasterClass.java index dab2667..839faef 100644 --- a/src/pkg1/MasterClass.java +++ b/src/pkg1/MasterClass.java @@ -3,5 +3,8 @@ public class MasterClass { public static void main(String[] args) { Hitesh_Class hks = new Hitesh_Class(); hks.sayHello(); + Aryansh_Class ars = new Aryansh_Class(); + ars.createBinaryTree(); + ars.preorder(ars.root); } }