• <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 閱讀(1029) 評論(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;
            }

            思思久久好好热精品国产| 香蕉久久AⅤ一区二区三区| 久久久99精品一区二区| 精品久久久无码中文字幕| 久久综合亚洲色HEZYO国产| 狠狠色噜噜色狠狠狠综合久久| 久久久www免费人成精品| 久久99国产精品久久久 | 精品综合久久久久久97超人 | 精品久久久久久国产三级| 婷婷久久精品国产| 狠狠久久亚洲欧美专区| 91麻豆国产精品91久久久| 国产一久久香蕉国产线看观看| 国产综合精品久久亚洲| 人妻精品久久久久中文字幕69| 久久精品中文字幕有码| 色欲综合久久中文字幕网| 狠狠色丁香久久婷婷综合| 精品久久久久中文字| 99久久精品费精品国产一区二区| 中文字幕乱码人妻无码久久| 99久久精品国产毛片| 精品综合久久久久久88小说| 中文字幕久久波多野结衣av| 久久久久综合国产欧美一区二区| 久久久精品一区二区三区| 国产麻豆精品久久一二三| 国产成人久久精品激情| 2020久久精品亚洲热综合一本| 久久男人AV资源网站| 精品一区二区久久| 人妻无码αv中文字幕久久琪琪布 人妻无码久久一区二区三区免费 人妻无码中文久久久久专区 | 欧美激情精品久久久久久久| 国产A级毛片久久久精品毛片| 69久久夜色精品国产69| 亚洲中文字幕久久精品无码APP| 久久大香萑太香蕉av| 精品国产99久久久久久麻豆 | 99久久99久久| 99久久国产综合精品麻豆|