problemscpp
A collection of my answers to algorithm problems in c++.
Public 成员函数 | Public 属性 | 所有成员列表
acwing::acwing4208::trie_node结构体 参考

字典树 更多...

#include <acwing.h>

Public 成员函数

 trie_node (int val, trie_node *father)
 
int count ()
 分支计数 更多...
 
void display ()
 显示 更多...
 
void insert (string str)
 反向插入 更多...
 

Public 属性

trie_nodefather
 父节点 更多...
 
trie_nodenexts [10] {}
 子节点 更多...
 
int val
 更多...
 

详细描述

字典树

在文件 acwing.h274 行定义.

构造及析构函数说明

◆ trie_node()

acwing::acwing4208::trie_node::trie_node ( int  val,
trie_node father 
)
inline

在文件 acwing.h288 行定义.

288: val(val), father(father){};
trie_node * father
父节点
Definition: acwing.h:282

被这些函数引用 insert().

成员函数说明

◆ count()

int acwing::acwing4208::trie_node::count ( )

分支计数

返回
分支计数

在文件 acwing.cpp754 行定义.

754 {
755 int count = 0;
756 bool flag = true;
757 for(auto *next: this->nexts) {
758 if(next != nullptr) {
759 flag = false;
760 count += next->count();
761 }
762 }
763 if(flag) {
764 return 1;
765 }
766 return count;
767 }
int count()
分支计数
Definition: acwing.cpp:754
trie_node * nexts[10]
子节点
Definition: acwing.h:286

引用了 count() , 以及 nexts.

被这些函数引用 count().

◆ display()

void acwing::acwing4208::trie_node::display ( )

显示

在文件 acwing.cpp736 行定义.

736 {
737 bool flag = true;
738 for(auto *next: this->nexts) {
739 if(next != nullptr) {
740 flag = false;
741 next->display();
742 }
743 }
744 if(flag) {
745 const auto *current = this;
746 while(current->val != -1) {
747 cout << static_cast<char>(current->val + '0');
748 current = current->father;
749 }
750 cout << " ";
751 }
752 }

引用了 nexts.

◆ insert()

void acwing::acwing4208::trie_node::insert ( string  str)

反向插入

参数
str插入的字符串

在文件 acwing.cpp726 行定义.

726 {
727 if(str.length() == 0) {
728 return;
729 }
730 if(this->nexts[str[0] - '0'] == nullptr) {
731 this->nexts[str[0] - '0'] = new trie_node(str[0] - '0', this);
732 }
733 this->nexts[str[0] - '0']->insert(str.substr(1));
734 }
trie_node(int val, trie_node *father)
Definition: acwing.h:288
void insert(string str)
反向插入
Definition: acwing.cpp:726

引用了 trie_node(), insert() , 以及 nexts.

被这些函数引用 insert().

类成员变量说明

◆ father

trie_node* acwing::acwing4208::trie_node::father

父节点

在文件 acwing.h282 行定义.

◆ nexts

trie_node* acwing::acwing4208::trie_node::nexts[10] {}

子节点

在文件 acwing.h286 行定义.

被这些函数引用 count(), display() , 以及 insert().

◆ val

int acwing::acwing4208::trie_node::val

在文件 acwing.h278 行定义.


该结构体的文档由以下文件生成: