• <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++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            Trie樹

            Posted on 2009-08-28 10:32 reiks 閱讀(1029) 評(píng)論(0)  編輯 收藏 引用 所屬分類: 算法與數(shù)據(jù)結(jié)構(gòu)
            /*
            Name: Trie樹的基本實(shí)現(xiàn)
            Author: MaiK
            Description: Trie樹的基本實(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;
            }

            18禁黄久久久AAA片| 日韩人妻无码一区二区三区久久| 国产精品美女久久久网AV| 99久久无码一区人妻| 亚洲精品国产美女久久久| 久久久久久久免费视频| 国产精品一区二区久久精品无码 | 天天影视色香欲综合久久| 理论片午午伦夜理片久久| 久久精品中文无码资源站| 亚洲欧美日韩精品久久亚洲区| 久久精品国产69国产精品亚洲 | 77777亚洲午夜久久多喷| 久久人人妻人人爽人人爽| 亚洲伊人久久精品影院| 99999久久久久久亚洲| 久久99国产乱子伦精品免费| 久久久久久久尹人综合网亚洲 | 女人高潮久久久叫人喷水| 伊人色综合久久天天人手人婷| 18岁日韩内射颜射午夜久久成人| 狠狠干狠狠久久| 人妻少妇久久中文字幕| 亚洲欧洲精品成人久久奇米网| 久久不见久久见免费视频7| 99久久国产亚洲高清观看2024 | 国产精品久久网| 久久99精品久久久久久秒播| 97久久超碰国产精品旧版| 开心久久婷婷综合中文字幕| A狠狠久久蜜臀婷色中文网| 色综合久久中文字幕综合网| 99久久婷婷国产一区二区| 亚洲国产成人精品91久久久 | 久久一区二区免费播放| 国产精品久久久久天天影视| 欧美日韩精品久久久免费观看| 久久91亚洲人成电影网站| 久久久久九国产精品| 亚洲国产精品成人久久| 久久精品午夜一区二区福利|