• <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) 評(píng)論(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;
            }

            日本亚洲色大成网站WWW久久| 精品国产乱码久久久久久人妻| 久久ww精品w免费人成| 久久天堂AV综合合色蜜桃网| 久久夜色tv网站| 久久综合视频网站| 97久久国产亚洲精品超碰热| 99久久无码一区人妻| 久久精品国产亚洲AV久| 久久99国产精品99久久| 综合久久给合久久狠狠狠97色| 久久精品www人人爽人人| 午夜精品久久久久久影视777| 久久免费的精品国产V∧| 久久久无码精品午夜| 久久精品视频免费| 精品久久亚洲中文无码| 国产高潮国产高潮久久久91| 欧美日韩精品久久免费| 久久精品国产精品亚洲人人| 国产精品一区二区久久不卡 | 亚洲欧美日韩久久精品| 久久国产免费观看精品| 久久A级毛片免费观看| 久久人妻AV中文字幕| 一本一道久久a久久精品综合| 97精品国产97久久久久久免费| 久久国产免费观看精品3| 777午夜精品久久av蜜臀| 久久国产亚洲精品| 亚洲综合久久久| 日韩欧美亚洲国产精品字幕久久久| 94久久国产乱子伦精品免费| 99久久无色码中文字幕| 久久久噜噜噜www成人网| 亚洲国产精品无码久久久秋霞2 | 亚洲国产成人久久综合碰| 精品久久久久国产免费| 国产精品热久久无码av| 精品视频久久久久| 久久无码一区二区三区少妇|