Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BTree {
- private TreeNode root;
- private class TreeNode{
- private TreeNode left;
- private TreeNode right;
- private int data;
- public TreeNode(int data)
- {
- this.data=data;
- }
- }
- public void createBinaryTree()
- {
- 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);
- //TreeNode sixth=new TreeNode(6);
- root=first; //root
- first.left=second;
- first.right=third; ///second<==first-->third
- second.left=fourth;
- second.right=fifth;
- }
- public static void main(String[] args) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment