A recursive algorithm for constructing two-fork tree by First order and middle sequence traversal sequence

Source: Internet
Author: User

1 voidPreinord (CharPreord[],CharInord[],intJintJintKintH, Bitree *t)2 {3     //First Order sequence: i->j, sequence k->h, establishing two-fork-tree T4     intm;5(*t) =NewBinode;6(*t)->data =Preord[i];7m =K;8      while(Inord[m]! =Preord[i])9     {Tenm++; One     } A     if(M = =k) -     { -         //Shora the(*t)->lchild =NULL; -     } -     Else -     { +Preinord (Preord, Inord, i +1, i + M-k, K, M-1, & (*t)lchild)); -     } +     if(M = =h) A     { at         //right sub-tree empty -(*t)->rchild =NULL; -     } -     Else -     { -Preinord (Preord, Inord, i + m-k +1, J, M +1, H, & (*t)lchild)); in     } - } to  + voidCreatebitree (CharPreord[],CharInord[],intN, bitree Root) - { the     if(N <=0) *     { $Root =NULL;Panax Notoginseng     } -     Else the     { +Preinord (Preord, Inord,1N1, N, &root); A     } the}

A recursive algorithm for constructing two-fork tree by First order and middle sequence traversal sequence

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.