• <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的技術博客

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

            Trie樹

            Posted on 2009-08-28 10:32 reiks 閱讀(1031) 評論(0)  編輯 收藏 引用 所屬分類: 算法與數據結構
            /*
            Name: Trie樹的基本實現
            Author: MaiK
            Description: Trie樹的基本實現 ,包括查找 插入和刪除操作(衛星數據可以因情況而異)
            */

            #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热免费| 中文字幕日本人妻久久久免费| 久久无码人妻精品一区二区三区| 久久亚洲国产欧洲精品一| 久久精品国产99久久丝袜| 香蕉久久AⅤ一区二区三区| 久久笫一福利免费导航 | 伊人 久久 精品| 久久久午夜精品| 国产精品免费福利久久| 久久精品国产精品亜洲毛片| 久久www免费人成看片| 97久久精品无码一区二区天美| 久久久久久毛片免费看 | 精品久久久久久中文字幕| 国产精品久久久天天影视香蕉 | 久久无码一区二区三区少妇| 亚洲va久久久噜噜噜久久男同| 久久综合九色综合精品| 亚洲欧美成人久久综合中文网| 久久久久久国产精品免费无码| 久久精品国产亚洲Aⅴ蜜臀色欲| 国产成人精品综合久久久| 大美女久久久久久j久久| 中文字幕乱码人妻无码久久| 午夜不卡888久久| 久久久久久伊人高潮影院| 亚洲国产精品热久久| 亚洲国产精品无码成人片久久| 久久精品三级视频| 国产精品一区二区久久| 久久久精品2019免费观看| 久久精品国产日本波多野结衣| 久久强奷乱码老熟女网站| 久久综合九色综合久99| 少妇内射兰兰久久| 日韩av无码久久精品免费| 久久丫忘忧草产品| 久久久久久曰本AV免费免费| 天天做夜夜做久久做狠狠|