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

            久久99精品久久久久久水蜜桃| 无码任你躁久久久久久久| 久久91精品久久91综合| 国产精品欧美久久久久天天影视| 久久精品亚洲福利| 国内精品伊人久久久久av一坑| 国产免费久久久久久无码| 中文字幕人妻色偷偷久久| 亚洲欧美精品伊人久久| 亚洲va中文字幕无码久久| 久久国产免费直播| 国产欧美久久一区二区| 久久久无码精品亚洲日韩京东传媒| 久久99亚洲网美利坚合众国| 综合久久精品色| 国产一区二区精品久久凹凸| AAA级久久久精品无码片| 伊人色综合九久久天天蜜桃| 国产精品日韩欧美久久综合| 久久亚洲欧美日本精品| 精品熟女少妇a∨免费久久| 漂亮人妻被中出中文字幕久久| 久久国产香蕉一区精品| 91性高湖久久久久| 久久九九青青国产精品| 97久久精品无码一区二区| 成人久久免费网站| 亚洲中文久久精品无码ww16| 污污内射久久一区二区欧美日韩| 国产精品免费久久久久久久久| 久久免费小视频| 狠狠色综合久久久久尤物| 国内精品久久久久久久久| 9999国产精品欧美久久久久久| 91精品国产综合久久香蕉| 国产精品内射久久久久欢欢| 久久精品国产国产精品四凭| 久久久久亚洲?V成人无码| 久久频这里精品99香蕉久| 久久久久av无码免费网| 久久er99热精品一区二区|