Java Data structure (binary tree)

Source: Internet
Author: User

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}


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( >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(! =value) { the             if( >value) { *Current =Current.leftchild; $}Else{Panax NotoginsengCurrent =Current.rightchild; -             } the             if(Current = =NULL){ +                 return NULL; A             } the         } +         returnCurrent ; -     } $}

Java Data structure (binary tree)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.