diff --git a/src-java/BinaryTree Implementation b/src-java/BinaryTree Implementation new file mode 100644 index 0000000..4fd763f --- /dev/null +++ b/src-java/BinaryTree Implementation @@ -0,0 +1,31 @@ +public class BinaryTree{ + private TreeNode root; + private class TreeNode{ + private TreeNode left; + private TreeNode right; + private TreeNode null; + + public TreeNode(int data){ + this.data=data; + } + } + + public void createBT(){ + TreeNode first=new TreeNode(1); + TreeNode second=new TreeNode(2); + TreeNode third=new TreeNode(3); + TreeNode fourth=new TreeNode(4); + TreeNode fifth=new TreeNode(5); + + root=first; + first.left=second; + first.right=third; + second.left=fourth; + second.right=fifth; + } + + public static void main(String args[]){ + BinaryTree bt=new BinaryTree(); + bt.createBT(); + } +} diff --git a/src-java/BinaryTreeImplementation b/src-java/BinaryTreeImplementation new file mode 100644 index 0000000..4fd763f --- /dev/null +++ b/src-java/BinaryTreeImplementation @@ -0,0 +1,31 @@ +public class BinaryTree{ + private TreeNode root; + private class TreeNode{ + private TreeNode left; + private TreeNode right; + private TreeNode null; + + public TreeNode(int data){ + this.data=data; + } + } + + public void createBT(){ + TreeNode first=new TreeNode(1); + TreeNode second=new TreeNode(2); + TreeNode third=new TreeNode(3); + TreeNode fourth=new TreeNode(4); + TreeNode fifth=new TreeNode(5); + + root=first; + first.left=second; + first.right=third; + second.left=fourth; + second.right=fifth; + } + + public static void main(String args[]){ + BinaryTree bt=new BinaryTree(); + bt.createBT(); + } +}