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

            精品久久人人爽天天玩人人妻| 久久精品中文字幕无码绿巨人| 国产精品一区二区久久| 97久久精品无码一区二区| 久久99毛片免费观看不卡| 久久久久亚洲精品天堂久久久久久 | 精品久久久无码人妻中文字幕豆芽| 久久SE精品一区二区| 久久天天躁狠狠躁夜夜躁2O2O| 一本伊大人香蕉久久网手机| 久久午夜无码鲁丝片午夜精品| 国产精品99久久久久久宅男小说| 久久精品国产亚洲av麻豆色欲| 99热成人精品热久久669| 亚洲欧洲中文日韩久久AV乱码| 久久综合亚洲欧美成人| 国产99久久九九精品无码| 一本一本久久aa综合精品| 大香网伊人久久综合网2020| 亚洲日本va中文字幕久久| 精品欧美一区二区三区久久久| 亚洲精品国产美女久久久| 日本亚洲色大成网站WWW久久| 久久国产欧美日韩精品| 麻豆av久久av盛宴av| 91精品国产91久久| 精品国产乱码久久久久久1区2区| 亚洲国产香蕉人人爽成AV片久久 | 久久婷婷色综合一区二区| 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲 | 久久99久久99小草精品免视看| 亚洲精品美女久久777777| 亚洲欧美日韩久久精品| 精品视频久久久久| 亚洲一区二区三区日本久久九| 久久99国内精品自在现线| 无遮挡粉嫩小泬久久久久久久| 中文字幕人妻色偷偷久久| 99久久香蕉国产线看观香| 思思久久99热只有频精品66| 欧美大战日韩91综合一区婷婷久久青草|