• <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++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            Trie樹

            Posted on 2009-08-28 10:32 reiks 閱讀(1040) 評論(0)  編輯 收藏 引用 所屬分類: 算法與數(shù)據(jù)結(jié)構(gòu)
            /*
            Name: Trie樹的基本實(shí)現(xiàn)
            Author: MaiK
            Description: Trie樹的基本實(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;
            }

            色综合久久中文色婷婷| 日韩精品国产自在久久现线拍| 亚洲&#228;v永久无码精品天堂久久| 精品久久久久久国产| 欧美精品丝袜久久久中文字幕 | 久久久国产精华液| 97久久精品无码一区二区| 精品久久久久久无码中文字幕| 伊人久久大香线蕉综合5g| 狠狠色丁香婷婷久久综合不卡| 欧美粉嫩小泬久久久久久久 | 久久亚洲精品国产精品| 久久有码中文字幕| 亚洲国产精品久久久久婷婷软件| 亚洲国产视频久久| 久久www免费人成精品香蕉| 色综合久久无码五十路人妻| 色婷婷综合久久久久中文字幕| 久久99国产精品一区二区| A级毛片无码久久精品免费| 久久午夜福利电影| 久久国产精品免费一区二区三区 | 久久久久国产精品| 久久久老熟女一区二区三区| 九九精品久久久久久噜噜| 久久精品国产亚洲Aⅴ香蕉| 久久精品国产亚洲av水果派| 精品综合久久久久久97| 少妇人妻综合久久中文字幕| 一本久道久久综合狠狠躁AV| 久久国产精品一区| 久久精品国产99国产精品| 91精品久久久久久无码| 女人香蕉久久**毛片精品| 青青草国产精品久久| 一本色道久久88加勒比—综合| 久久九九全国免费| 久久人人爽人人精品视频| 天天做夜夜做久久做狠狠| 国内精品综合久久久40p| 99久久夜色精品国产网站|