说明:
以下代码是个人按照自己的理解写的,可能有错误或者不太规范的地方,欢迎指出!
代码如下:
//插入、删除、查询、遍历四种操作
//注意:四种操作的函数实现中,T都是指向上一个结点的指针,以此方便操作。
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const double eps = 1e-6;
const int INF = 2e9;
const LL LNF = 9e18;
const int mod = 1e9+7;
const int maxn = 100+10;
typedef struct node
{
bool exist; //是否存在单词
int cnt; //作为多少个单词的前缀,不算自己
struct node *next[26];
void init()
{
exist = cnt = 0;
memset(next,0,sizeof(0));
}
}Node, *Tree;
void insert(Tree &T, char *s, int k)
{
if(!T)
{
T = new Node;
T->init();
}
if(!s[k])