void CreateTre(TreeNode **root,deque<int> &p)
{
if ((*p.begin()) == 0)
{
*root = nullptr;
p.pop_front();
}
else
{
*root = new TreeNode(*p.begin());
//cout << *p.begin() << " ";
p.pop_front();
CreateTre(&((*root)->left), p);
CreateTre(&((*root)->right), p);
}
}
void FirstTraver(TreeNode *root)
{
if (root == nullptr) return;
cout << root->val << " ";
FirstTraver(root->left);
FirstTraver(root->right);
}
void FloorTraver(TreeNode *root)
{
if (root == nullptr) return;
queue<TreeNode *> vec;
vec.push(root);
TreeNode *fro = nullptr;
TreeNode *bac = nullptr;
while (!vec.empty())
{
fro = vec.front();
bac = vec.back();
if (fro->left != nullptr) vec.push(fro->left);
if (fro->right != nullptr) vec.push(fro->right);
while (fro != bac)
{
cout << fro->val << " ";
vec.pop();
fro = vec.front();
if (fro->left != nullptr) vec.push(fro->left);
if (fro->right != nullptr) vec.push(fro->right);
}
cout << fro->val << endl;
vec.pop();
}
}