• <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精品国产9l久久久久| 人妻丰满?V无码久久不卡| 久久国产欧美日韩精品| 国产一区二区三区久久| 一本久久a久久精品vr综合| 一级做a爰片久久毛片16| 麻豆精品久久久久久久99蜜桃| 99久久精品影院老鸭窝| 久久精品成人欧美大片| 国产精品va久久久久久久| 久久精品aⅴ无码中文字字幕不卡| 66精品综合久久久久久久| 久久综合九色综合网站| 国产精品九九久久免费视频| 久久久久亚洲av无码专区| 日韩欧美亚洲综合久久| 精品多毛少妇人妻AV免费久久| 无码国内精品久久人妻| 亚洲伊人久久精品影院| 午夜精品久久久久久影视riav| 色偷偷888欧美精品久久久| 久久亚洲私人国产精品vA | 亚洲午夜精品久久久久久app| 热久久国产精品| 中文字幕久久欲求不满| 无码精品久久久天天影视| 一本色道久久HEZYO无码| 一本一本久久A久久综合精品| 久久国产亚洲精品| 精品综合久久久久久97| 99精品久久精品一区二区| 久久综合九色综合网站| 伊人久久大香线蕉av不卡| 人妻精品久久久久中文字幕69| 久久久女人与动物群交毛片| 狠狠88综合久久久久综合网 | 久久久精品免费国产四虎| 国产精品天天影视久久综合网|