C++实现字典树的增删查写前缀打印
//
// Created by jal on 19-3-9.
//
#include <bits/stdc++.h>
using namespace std;
const int SIZE = 26;
struct Node{
int sum;
bool isEnd;
char val;
vector<Node*>son;
Node(char val):
sum(0),isEnd(false),val(val){
son.resize(SIZE);
for(auto& node : son){
node = NULL;
}
}
};
struct Trie{
//字典树,实现单词的增删查写
Node* root;
Trie(){
root = new Node('a');
}
/*
* 往字典树中插入字符串
*/
void insert(string s){
if(s.size() <= 0 || s == "")return;
Node* node = root;
for(auto& c: s){
int p = c - 'a';
if(NULL == node->son[p]){
node-