按先序遍历序列建立一个二叉树的二叉链表,并按先序遍历、中序遍历、后序遍历将其输出。
测试用例1
-+a##*b##c##/d##e##↵
期待输出1
前序遍历结果:- + a * b c / d e ↵
中序遍历结果:a + b * c - d / e ↵
后序遍历结果:a b c * + d e / - ↵
#include <iostream>
#include <list>
#include <string>
using namespace std;
struct tree
{
char data;
tree* left;
tree* right;
tree()
:left(NULL),right(NULL)
{
}
};
string str;
int curIndex;
void CreateTree(tree* node);
void PreorderOutput(tree