Node nodes:
1 Public classNode {2 Public Longdata;3 PublicString SData;4 PublicNode leftchild;5 PublicNode rightchild;6 PublicNode (Longdata,string SData) {7 This. data =data;8 This. SData =SData;9 }Ten}
Tree:
1 Public classTree {2 PublicNode Root;3 4 Public voidInsertLongvalue,string svalue) {5Node NewNode =NewNode (value,svalue);6Node current =Root;7 Node parent;8 if(Root = =NULL){9Root =NewNode;Ten return; One}Else{ A while(true){ -Parent =Current ; - if(Current.data >value) { theCurrent =Current.leftchild; - if(Current = =NULL){ -Parent.leftchild =NewNode; - return ; + } -}Else{ +Current =Current.rightchild; A if(Current = =NULL){ atParent.rightchild =NewNode; - return; - } - } - } - } in } - to PublicNode Find (Longvalue) { +Node current =Root; - while(Current.data! =value) { the if(Current.data >value) { *Current =Current.leftchild; $}Else{Panax NotoginsengCurrent =Current.rightchild; - } the if(Current = =NULL){ + return NULL; A } the } + returnCurrent ; - } $}
Java Data structure (binary tree)