• <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久久国产热无码精品免费| 久久精品草草草| 久久99精品久久久久久| 久久免费视频一区| 浪潮AV色综合久久天堂| 久久久亚洲精品蜜桃臀| 久久偷看各类wc女厕嘘嘘| 欧美激情精品久久久久久久| 午夜精品久久久久久中宇| 久久人人爽人人爽AV片| 国产一久久香蕉国产线看观看 | 武侠古典久久婷婷狼人伊人| 久久久久亚洲AV无码专区体验| 欧美日韩中文字幕久久久不卡 | 伊人久久五月天| 精品一久久香蕉国产线看播放| 国内精品久久久久影院一蜜桃| 无码8090精品久久一区| 久久精品无码一区二区日韩AV| 国产精品无码久久综合| 中文字幕久久精品无码| 久久午夜福利无码1000合集| 精品久久久久久国产牛牛app| 91精品国产综合久久精品| 久久国产精品77777| 久久久久久久久久久久中文字幕| 久久精品人人做人人爽电影| 久久综合鬼色88久久精品综合自在自线噜噜| 久久最新精品国产| 日韩亚洲欧美久久久www综合网| 久久91综合国产91久久精品| 粉嫩小泬无遮挡久久久久久| 国产精品九九九久久九九| 国产精品毛片久久久久久久| 久久精品国产亚洲网站| 94久久国产乱子伦精品免费 | 香蕉久久久久久狠狠色| 青青热久久国产久精品 | 久久国产乱子伦精品免费强| aaa级精品久久久国产片| 中文字幕久久欲求不满|