• <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;
            }

            国产精品一区二区久久国产| 久久性精品| 四虎国产精品免费久久| 97久久国产综合精品女不卡 | 精品国产乱码久久久久久1区2区 | 久久久久久国产精品无码下载| 成人午夜精品无码区久久| 精品久久久久久综合日本| 久久久久噜噜噜亚洲熟女综合| 色欲久久久天天天综合网精品| 18岁日韩内射颜射午夜久久成人| 伊人久久大香线蕉综合Av| 国产精品热久久毛片| 无码人妻精品一区二区三区久久久 | 99久久精品免费观看国产| 久久精品卫校国产小美女| 成人午夜精品久久久久久久小说 | 99久久国产免费福利| 久久不见久久见免费视频7| 亚洲人成网站999久久久综合| 一本大道加勒比久久综合| 久久久噜噜噜久久中文福利| 精品久久久久久无码不卡| 国产午夜精品久久久久九九| 国产精品一区二区久久不卡| 伊人久久大香线蕉av不变影院| 久久久久一本毛久久久| 品成人欧美大片久久国产欧美... 品成人欧美大片久久国产欧美 | 人妻精品久久久久中文字幕| 久久国产亚洲精品| 久久综合日本熟妇| 国产精品美女久久久久AV福利| 97久久久久人妻精品专区| 亚洲精品无码久久千人斩| 精品国产乱码久久久久久人妻| 99久久免费国产精品特黄| 亚洲欧美日韩精品久久亚洲区 | 亚洲综合精品香蕉久久网97| 中文字幕亚洲综合久久| 97精品伊人久久久大香线蕉| 久久精品成人|