1

我正在用 c 编写用于字符串查找的三叉树。

到目前为止,我能够存储字符串并检查字符串是否存在。

示例插入

Node *node_link(Node *this, char *line) {
 26   if(!this) {
 27     this = node_create(*line);
 28   }
 29   if(*line < this->ch) {
 30     this->left = node_link(this->left, line);
 31   } else if(*line == this->ch) {
 32     if(*(++line) == 0) {
 33       this->there = TRUE;
 34       return this;
 35     } else {
 36       this->mid = node_link(this->mid, line);
 37     }
 38   } else {
 39     this->right = node_link(this->right, line);
 40   }
 41   return this;
 42 }

我需要取回我插入的字符串。例如,如果我插入

hat
cat
catpost
tent
tents
square
squarish

我应该能够提取具有相同字符串的列表。如果我进行树遍历(DFS),我不会得到它。如何获取存储项目的列表?

示例遍历

void node_walk_link(Node *this, char *line) {
 44   if(this) {
 45     node_walk_link(this->left, line);
 46     node_walk_link(this->right, line);
 47     node_walk_link(this->mid, line_push(line, this->ch, 0));
 48   }
 49 }

另外如何找到两个三元树的联合?有来自两棵树的项目,没有重复。

4

0 回答 0