Implementation of BInary Tree in java -
i trying implement binary tree in java , here code:
class testclass {      public static  void newnode(int , node root,){                root = new  node(a);               system.out.println(root.data);   // printing out 22                                            }     public static void main(string args[] ) throws ioexception {         node root = null;       newnode(22,root);       system.out.println(root.data);  // giving nullpointerexception       }     }     class node{          node left ;         node right;         int data ;          node(int dataa){              this.data = dataa;         }     } i not insert new node in tree , value of root not changes
when call newnode function getting correct value of root node in main function gives me null point exception
why value of root not updating 
class testclass {      public static  node newnode(int , node root){         root = new  node(a);         system.out.println(root.data);   // printing out 22         return root;     }     public static void main(string args[] ) throws ioexception {         node root = null;         root = newnode(22,root);         system.out.println(root.data);  // giving nullpointerexception     } } try this
Comments
Post a Comment