文章
1
粉丝
80
获赞
0
访问
1.2k
# 地址:1161 - 二叉树遍历 _N诺计算机考研 (noobdream.com)
#include <iostream>
#include <string>
using namespace std;
struct Node {
char data;
struct Node* lchild, *rchild;
};
Node* preorder(string str, int &i) {
char data = str[i++];
if (data == '#') {
return NULL;
}
Node *node = new Node;
node->data = data;
node->lchild = preorder(str, i);
node->rchild = preorder(str, i);
return node;
}
void Inorder(Node *node) {
if (node == NULL)
return;
Inorder(node->lchild);
cout << node->data << " ";
Inorder(node->rchild);
}
int main() {
string str;
 ...
登录后发布评论
判断语句改为
if (data == '#' || i > str.length()) {
return NULL;
}