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

            亚洲午夜久久影院| 久久久久久噜噜精品免费直播 | 激情久久久久久久久久| 国产精品久久久久天天影视| 久久91精品久久91综合| 久久九色综合九色99伊人| 一本久道久久综合狠狠躁AV| 日本久久久久久久久久| 久久经典免费视频| 999久久久免费精品国产| 久久精品视频91| 精品久久久久久无码专区不卡| 久久婷婷色综合一区二区| 久久午夜无码鲁丝片秋霞 | 大蕉久久伊人中文字幕| 国产毛片欧美毛片久久久| 国产成人香蕉久久久久| 久久亚洲中文字幕精品有坂深雪 | 亚洲中文久久精品无码ww16| 大蕉久久伊人中文字幕| 精品久久久久久无码专区不卡| 久久这里只有精品视频99| 精品一区二区久久| 色欲久久久天天天综合网| 精品久久久久中文字| 99久久久精品| 亚洲AV无码久久精品蜜桃| 一本一道久久a久久精品综合| 91超碰碰碰碰久久久久久综合 | 香蕉久久夜色精品国产小说| 欧美黑人激情性久久| 久久久久久一区国产精品| 精品欧美一区二区三区久久久| av国内精品久久久久影院| 久久久久久亚洲精品成人| 久久精品国产乱子伦| 久久久午夜精品福利内容| 日本亚洲色大成网站WWW久久| 国产亚洲精久久久久久无码AV| 99久久精品无码一区二区毛片| 久久中文娱乐网|