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;
}
只有注冊用戶
登錄
后才能發(fā)表評論。
【推薦】100%開源!大型工業(yè)跨平臺軟件C++源碼提供,建模,組態(tài)!
相關(guān)文章:
最大流 Edmonds-Karp
樹狀數(shù)組
匈牙利算法
并查集
Topsort
Trie樹
大整數(shù)乘除小整數(shù)
RMQ問題ST算法
MST-Kruskal
組合數(shù)
網(wǎng)站導(dǎo)航:
博客園
IT新聞
BlogJava
博問
Chat2DB
管理
Powered by:
C++博客
Copyright © reiks
日歷
<
2025年8月
>
日
一
二
三
四
五
六
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
常用鏈接
我的隨筆
我的評論
我參與的隨筆
留言簿
給我留言
查看公開留言
查看私人留言
隨筆分類
Direct3D(1)
算法與數(shù)據(jù)結(jié)構(gòu)(15)
心情隨筆(1)
隨筆檔案
2011年5月 (2)
2009年8月 (15)
搜索
最新評論
1.?re: 如何在Direct3D里面使用GDI
為什么我用IDirect3DSurface9的GetDC接口得到dc,然后畫矩形框顯示不出來?
獲取dc是成功的
--herman
2.?re: 如何在Direct3D里面使用GDI
很想知道,為什么要在D3D里使用GDI?
--K.V
閱讀排行榜
1.?RMQ問題ST算法(3574)
2.?如何在Direct3D里面使用GDI(1641)
3.?Trie樹(1040)
4.?最大流 Edmonds-Karp(764)
5.?匈牙利算法(640)
6.?Topsort(560)
7.?MST-PRIM(545)
8.?并查集(479)
9.?大整數(shù)乘除小整數(shù)(447)
10.?樹狀數(shù)組(392)
評論排行榜
1.?如何在Direct3D里面使用GDI(2)
2.?線段樹(0)
3.?MST-PRIM(0)
4.?Floyd(0)
5.?Dijkstra(0)
6.?全排列(0)
7.?組合數(shù)(0)
8.?MST-Kruskal(0)
9.?RMQ問題ST算法(0)
10.?大整數(shù)乘除小整數(shù)(0)
色综合久久中文色婷婷
|
日韩精品国产自在久久现线拍
|
亚洲äv永久无码精品天堂久久
|
精品久久久久久国产
|
欧美精品丝袜久久久中文字幕
|
久久久国产精华液
|
97久久精品无码一区二区
|
精品久久久久久无码中文字幕
|
伊人久久大香线蕉综合5g
|
狠狠色丁香婷婷久久综合不卡
|
欧美粉嫩小泬久久久久久久
|
久久亚洲精品国产精品
|
久久有码中文字幕
|
亚洲国产精品久久久久婷婷软件
|
亚洲国产视频久久
|
久久www免费人成精品香蕉
|
色综合久久无码五十路人妻
|
色婷婷综合久久久久中文字幕
|
久久99国产精品一区二区
|
A级毛片无码久久精品免费
|
久久午夜福利电影
|
久久国产精品免费一区二区三区
|
久久久久国产精品
|
久久久老熟女一区二区三区
|
九九精品久久久久久噜噜
|
久久精品国产亚洲Aⅴ香蕉
|
久久精品国产亚洲av水果派
|
精品综合久久久久久97
|
少妇人妻综合久久中文字幕
|
一本久道久久综合狠狠躁AV
|
久久国产精品一区
|
久久精品国产99国产精品
|
91精品久久久久久无码
|
女人香蕉久久**毛片精品
|
青青草国产精品久久
|
一本色道久久88加勒比—综合
|
久久九九全国免费
|
久久人人爽人人精品视频
|
天天做夜夜做久久做狠狠
|
国内精品综合久久久40p
|
99久久夜色精品国产网站
|