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