#include <iostream>
#include "raw.h"
#include <queue>
using namespace std;
void preOrder(node *root)
{
cout << root->val << " ";
if (root->l != nullptr)
{
preOrder(root->l);
}
if (root->r != nullptr)
{
preOrder(root->r);
}
cout << endl;
}
void inOrder(node *root)
{
if (root->l != nullptr)
{
inOrder(root->l);
}
cout << root->val << " ";
if (root->r != nullptr)
{
inOrder(root->r);
}
cout << endl;
}
void postOrder(node *root)
{
if (root == nullptr)
{
return ;
}
postOrder(root->l);
postOrder(root->r);
cout << root->val << " ";
cout << endl;
}
void levelOrder(node *root)
{
queue<node *> qu;
qu.push(root);
while (!qu.empty())
{
node *temp = qu.front();
que.pop();
cout << temp->val << " ";
if (temp->l != nullptr)
{
qu.push(temp->l);
}
if (temp->r != nullptr)
{
qu.push(temp->r);
}
}
cout << endl;
}
int main()
{
node *root = init();
preOrder(root);
inOrder(root);
postOrder(root);
levelOrder(root);
return 0;
}