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

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -