About binary sort Tree BST

Source: Internet
Author: User

1#include <stdio.h>2#include <stdlib.h>3 4typedefstructnode5 {6     DoubleW;7     structNode *l,*R;8}*Node;9 Ten voidBuild (Node &rt,Doublea)//achievements One { A     if(rt==NULL) -     { -rt=Newnode; thert->w=A; -Rt->l=0; -Rt->r=0; -     } +     Else -     { +         if(a<rt->W) ABuild (rt->l,a); at         Else -Build (rt->r,a); -     } - } - DoubleFinstructNode *RT)//Find the smallest right - { in     if(!RT) -         return 0; to     Else if(!rt->l) +         returnRt->W; -     Else the         returnFin (rt->l); * } $ Panax Notoginseng voidDelet (Node &rt,DoubleW)//Delete Right is W point - { the     if(!RT) +     { Aprintf"no, \ n"); the         return ; +     } -     Else if(rt->w<W) $Delet (rt->r,w); $     Else if(rt->w>W) -Delet (rt->l,w); -     Else if(rt->l&&rt->R) the     { -         structNode *tmp;Wuyitmp=RT; theTmp->w=fin (tmp->R); -Delet (tmp->r,tmp->W); Wu     } -     Else About     { $         structNode *T; -t=RT; -         if(rt->l) -Rt=rt->l; A         Else +Rt=rt->R; the         Delete(t); -     } $  the } the void inch(structNode *RT)//middle order the { the     if(RT) -     { in         inch(rt->l); theprintf"%LF",rt->W); the         inch(rt->R); About     } the     Else the         return ; the } + DoubleW; - intaim; the Bayi voidSearch (Node RT,int&CNT)//Find the first aim small the { the     if(RT) -     { -Search (rt->l,cnt); thecnt++; the         if(cnt==aim) the         { theW=rt->W; -             return; the         } theSearch (rt->r,cnt); the 94     }     the } the intMain () the {98     intN; Aboutscanf"%d",&n); -     structNode *Root;101root=0;102      for(intI=1; i<=n;i++)//Insert103     {104         DoubleA; thescanf"%LF",&a);106 Build (root,a);107     }108     inch(root);109printf"\ n"); thescanf"%d",&n);111      for(intI=1; i<=n;i++)//delete the     {113         DoubleA; thescanf"%LF",&a); the delet (root,a); the         inch(root);117printf"\ n");118     }119scanf"%d",&n); -      for(intI=1; i<=n;i++)121     {122scanf"%d",&aim); First AIM Small123         intCnt=0;124 search (root,cnt); theprintf"%lf\n", W);126     }127     return 0; - }129 /* the 9131 3 4 2 5 7 6 3.5 3.1 3.6 the 0133 3134 6135 7136 3137 138 */

About binary sort Tree BST

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: info-contact@alibabacloud.com 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.