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

            久久久久国产亚洲AV麻豆| 伊人久久大香线蕉综合影院首页| 99久久婷婷国产综合亚洲| www.久久热.com| 久久久久久久国产免费看| 麻豆精品久久久久久久99蜜桃| 亚洲狠狠婷婷综合久久蜜芽| 欧美激情精品久久久久| 久久精品视频一| 国产福利电影一区二区三区久久久久成人精品综合 | 青青草原1769久久免费播放| 久久性生大片免费观看性| 欧美大香线蕉线伊人久久| 久久本道久久综合伊人| 亚洲中文字幕无码久久2017| 久久精品国产精品亚洲| 久久国产精品-国产精品| 久久狠狠爱亚洲综合影院| 久久久久亚洲AV成人网人人软件| 亚洲av伊人久久综合密臀性色| 久久久久无码精品| 久久久久国产精品| 国产精品久久波多野结衣| 久久99热这里只有精品国产| 天天综合久久一二三区| 久久久WWW成人免费精品| 香蕉久久一区二区不卡无毒影院| 久久精品人人做人人爽97| 亚洲狠狠婷婷综合久久久久| 久久精品国产亚洲AV影院| 2019久久久高清456| 天天做夜夜做久久做狠狠| 久久丝袜精品中文字幕| 久久久久国产亚洲AV麻豆| 亚洲国产精品无码久久青草| 久久久久亚洲精品无码网址| 国产香蕉97碰碰久久人人| 久久免费大片| 久久婷婷色香五月综合激情| 亚洲va中文字幕无码久久| 99久久久精品|