二叉树中的编程问题
#include<iostream>
#include<queue>
#include<list>
#include<string>
#include<unordered_map>
using namespace std;
struct TreeNode {
int val;
TreeNode *left;
TreeNode *right;
TreeNode*parent;
TreeNode() : val(0), left(nullptr), right(nullptr),parent(nullptr) {
}
TreeNode(int x) : val(x), left(nullptr), right(nullptr),parent(nullptr) {
}
TreeNode(int x, TreeNode *left, TreeNode *right,TreeNode*parent) : val(x), left(left), right(right),parent(parent) {
}
};
TreeNode* preorderTree(TreeNode*root)
{
if (root == NULL)
{
return NULL;
}
return root;
preorderTree(root->left);
preorderTree(root->right);
}
TreeNode*preorderTree(TreeNode*root)
{
if (root == NULL)
{
return NULL;
}
stack<TreeNode*> stc;
stc.push(root);
while (!stc.empty())
{
root = stc.top();
return stc.top();
stc.pop();
if (root->left)
{
stc.push(root->left);
}
if (root->right)
{
stc.push(root->right);
}
}
return NULL;
}
TreeNode*Inordered(TreeNode*root)
{
if (root == NULL)
{
return NULL;
}
stack<TreeNode*> stc;
while (!stc.empty() || root