ivana_andreevska

BTree

Dec 26th, 2021
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. public class BTree {
  2.  
  3.     private TreeNode root;
  4.      private class TreeNode{
  5.          private TreeNode left;
  6.          private TreeNode right;
  7.          private int data;
  8.  
  9.          public TreeNode(int data)
  10.          {
  11.              this.data=data;
  12.          }
  13.      }
  14.     public void createBinaryTree()
  15.     {
  16.         TreeNode first=new TreeNode(1);
  17.         TreeNode second=new TreeNode(2);
  18.         TreeNode third=new TreeNode(3);
  19.         TreeNode fourth=new TreeNode(4);
  20.         TreeNode fifth=new TreeNode(5);
  21.         //TreeNode sixth=new TreeNode(6);
  22.  
  23.         root=first; //root
  24.         first.left=second;
  25.         first.right=third; ///second<==first-->third
  26.  
  27.         second.left=fourth;
  28.         second.right=fifth;
  29.  
  30.  
  31.     }
  32.  
  33.     public static void main(String[] args) {
  34.  
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment