字典树模版
2015-12-03 18:02
309 查看
定义结构体:
产生新节点:
这段代码根据要求可以不同形式的:
建字典树:
#define Max 13 struct dot { dot *next[Max]; int flag; } ;
产生新节点:
dot *newnode() { dot *temp=new dot; temp->flag=0; for(int i=0;i<Max;i++) temp->next[i]=NULL; return temp; }
这段代码根据要求可以不同形式的:
建字典树:
void tree(char *st,dot *root,int &k) { dot *p=root; int id=0; for(int i=0;i<strlen(st);i++) { id=st[i]-'a'; if(p->next[id]==NULL) { k++; p->next[id]=newnode(); } p=p->next[id]; } }删除操作:
void del(dot *t) { if(t==NULL) return ; for(int i=0;i<Max;i++) if(t->next[i]!=NULL) del(t->next[i]); delete t; }
相关文章推荐
- UITableView的contentSize
- 杭电1159Common Subsequence
- 迅为iTOP-4412开发板Ubuntu操作系统烧写方法
- POJ2828---线段树与逆序数&&DUTOJ1210---逆序对构造排列
- 字典树模版
- 如何应对居高不下的离职率?
- keepalived高级应用
- cryptico.js使用技巧
- QT 控件基础
- How can I install mySQL on CentOS without being root/su?
- 杭电1257 最少拦截系统
- Android 检测 手机硬件状态 的Utils
- 转----详解IOS开发应用之并发Dispatch Queues
- js基础篇——encodeURI 和encodeURIComponent
- Handling unhandled exceptions and signals
- 使用dos指令快速导出手机文件
- ios开发之block的使用,及注意事项
- 1024 杭电 max plus
- 点击tableView时触发事件,比如隐藏键盘
- Unity局部高效实时阴影的思考和实现