• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Reiks的技術(shù)博客

            C/C++/STL/Algorithm/D3D
            posts - 17, comments - 2, trackbacks - 0, articles - 0
              C++博客 :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            Trie樹(shù)

            Posted on 2009-08-28 10:32 reiks 閱讀(1040) 評(píng)論(0)  編輯 收藏 引用 所屬分類(lèi): 算法與數(shù)據(jù)結(jié)構(gòu)
            /*
            Name: Trie樹(shù)的基本實(shí)現(xiàn)
            Author: MaiK
            Description: Trie樹(shù)的基本實(shí)現(xiàn) ,包括查找 插入和刪除操作(衛(wèi)星數(shù)據(jù)可以因情況而異)
            */

            #include
            <algorithm>
            #include
            <iostream>
            using namespace std;

            const int sonnum=26,base='a';
            struct Trie
            {
                
            int num;  //to remember how many word can reach here,that is to say,prefix
                bool terminal;  //If terminal==true ,the current point has no following point
                struct Trie *son[sonnum];  //the following point
            }
            ;
            Trie 
            *NewTrie()// create a new node
            {
                Trie 
            *temp=new Trie;
                temp
            ->num=1;
                temp
            ->terminal=false;
                
            for (int i=0; i<sonnum; ++i)
                    temp
            ->son[i] = NULL;
                
            return temp;
            }

            void Insert(Trie *pnt,char *s,int len)// insert a new word to Trie tree
            {
                Trie 
            *temp=pnt;
                
            for (int i=0;i<len;++i)
                
            {
                    
            if (temp->son[s[i]-base]==NULL)
                        temp
            ->son[s[i]-base]=NewTrie();
                    
            else
                        temp
            ->son[s[i]-base]->num++;
                    temp
            =temp->son[s[i]-base];
                }

                temp
            ->terminal=true;
            }

            void Delete(Trie *pnt)  // delete the whole tree
            {
                
            if (pnt!=NULL)
                
            {
                    
            for (int i=0;i<sonnum;++i)
                        
            if (pnt->son[i]!=NULL)
                            Delete(pnt
            ->son[i]);
                    delete pnt;
                    pnt
            =NULL;
                }

            }

            Trie
            * Find(Trie *pnt,char *s,int len)  //trie to find the current word
            {
                Trie 
            *temp=pnt;
                
            for (int i=0;i<len;++i)
                    
            if (temp->son[s[i]-base]!=NULL)
                        temp
            =temp->son[s[i]-base];
                    
            else return NULL;
                
            return temp;
            }

            国产三级久久久精品麻豆三级| 国产精品久久久久天天影视| 中文字幕亚洲综合久久菠萝蜜 | 亚洲香蕉网久久综合影视| 久久99国产综合精品| 久久精品夜色噜噜亚洲A∨| 久久综合九色综合网站| 亚洲国产成人久久综合碰碰动漫3d | 久久婷婷五月综合97色一本一本 | 99久久国产精品免费一区二区| av午夜福利一片免费看久久| 理论片午午伦夜理片久久| 97久久精品人妻人人搡人人玩| 久久乐国产精品亚洲综合| 69国产成人综合久久精品| 精品国产99久久久久久麻豆| 久久久久噜噜噜亚洲熟女综合| 国产美女久久久| 久久综合亚洲欧美成人| 三级三级久久三级久久| 久久久久亚洲精品天堂久久久久久 | …久久精品99久久香蕉国产| 久久久久久国产a免费观看黄色大片 | 99久久国产综合精品女同图片| 亚洲国产成人久久综合区| 久久精品国产99久久香蕉| 亚洲一区中文字幕久久| 色综合久久精品中文字幕首页| 狠狠88综合久久久久综合网| 久久久亚洲欧洲日产国码aⅴ| 亚洲成色www久久网站夜月| 狠狠色婷婷久久一区二区| 国产精品久久久久免费a∨| 思思久久99热只有频精品66| 青春久久| 亚洲国产精品无码久久久不卡| 久久久久久久久波多野高潮| 久久精品国产亚洲精品2020| 久久国产高潮流白浆免费观看| 久久中文字幕一区二区| 久久精品国产福利国产琪琪|