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

            久久久无码精品亚洲日韩蜜臀浪潮| 久久精品无码一区二区三区日韩 | jizzjizz国产精品久久| 亚洲综合精品香蕉久久网| 久久久国产精品亚洲一区| 国产成人久久777777| 亚洲午夜无码久久久久小说| 无码久久精品国产亚洲Av影片| 青青青伊人色综合久久| 奇米影视7777久久精品人人爽| 国产成人精品久久一区二区三区| 久久99精品久久久久久9蜜桃| 国产精品亚洲综合久久| 国产激情久久久久影院| 一本色道久久99一综合| 久久99亚洲综合精品首页| 久久综合久久自在自线精品自| 久久精品18| 国产精品久久免费| 久久久无码一区二区三区 | 久久免费线看线看| 中文字幕日本人妻久久久免费| 国产午夜福利精品久久| 精品永久久福利一区二区| 国产成人精品三上悠亚久久| 久久精品亚洲精品国产欧美| 香港aa三级久久三级| 国内精品久久久久久99蜜桃| 中文精品久久久久人妻不卡| 久久天天躁狠狠躁夜夜2020一 | 久久久久久狠狠丁香| 亚洲中文字幕无码久久精品1| 日韩精品久久久久久久电影| 欧美激情精品久久久久久| 精品乱码久久久久久夜夜嗨| AA级片免费看视频久久| 久久AAAA片一区二区| 久久成人18免费网站| 久久久久亚洲av毛片大| 久久中文精品无码中文字幕| 亚洲国产成人精品91久久久|