• <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;
            }

            欧美日韩精品久久久久| 精品国产综合区久久久久久 | 精品久久久久久| 国产精品欧美久久久天天影视| 国产精品久久久久久| 欧美久久亚洲精品| 综合网日日天干夜夜久久| 国产成人久久激情91| 精品国产91久久久久久久a| 久久亚洲精品国产精品婷婷| 国产精品禁18久久久夂久| 久久免费视频一区| 国产一级持黄大片99久久| 久久精品国产清自在天天线| 亚洲国产精品无码久久久不卡 | 麻豆成人久久精品二区三区免费| 国产一久久香蕉国产线看观看| 伊人热热久久原色播放www| 99麻豆久久久国产精品免费 | 婷婷久久香蕉五月综合加勒比| 亚洲国产精品久久久久婷婷老年| 欧美久久久久久精选9999| 欧美日韩中文字幕久久伊人| 久久精品国产第一区二区三区 | 九九99精品久久久久久| 久久久久波多野结衣高潮| 久久久久亚洲AV成人网| 99国产精品久久久久久久成人热| 久久男人中文字幕资源站| 欧美777精品久久久久网| AV狠狠色丁香婷婷综合久久| 亚洲中文字幕无码久久综合网| 久久精品国产亚洲5555| 国产女人aaa级久久久级| 久久99热精品| 久久99精品国产99久久| 97精品伊人久久久大香线蕉| 国产精品99久久久久久董美香| 久久国产色AV免费观看| 成人久久综合网| 99久久综合国产精品二区|