#include “pch.h”
#include
#include <string.h>
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
struct Node {
char date;
//左右节点
Node* L;
Node* R;
};
Node* T;//创建指针
void creatNode(Node &T) {
char ch;
if ((ch = getchar() == "")//为了方便各位i同学理解,这里对空节点做一个处理
{
T = NULL;
}
else {
T = new Node;
T ->date = ch;
creatNode(T->L);//左节点
creatNode(T->R);//右节点
}
}
//前序遍历
void preOrder(Node*&T) {
if (T == NULL) {
return;
}
else {
cout << T->date << " ";//输出咱们提前做的空节点标记
preOrder(T->L);//开始递归
preOrder(T->R);//左孩子访问完成
}
}
//中序遍历
void inOrder(Node*&T) {
if (T == NULL) {
return;
}
else {
cout << T->date << " ";//输出咱们提前做的空节点标记
inOrder(T->L);//开始递归
inOrder(T->R);//左访问完成
}
}
//后续遍历
void posOrder(Node*&T) {
if (T == NULL) {
return;
}
else {
posOrder(T->L);
posOrder(T->R);
cout << T->date << " ";
}
}
int main() {
cout << “afadjahd” << endl;
creatNode(T);
cout << <<;
preOrder;
cout << ;
inorder(T);
cout << ;
posOrder;
endl;
delete T;
return 0;
}