#include <iostream>
#include <vector>
using namespace std;
struct Node
{
int data;
Node *left;
Node *right;
Node(int val)
{
data = val;
left = right = NULL;
}
};
Node *build()
{
Node *root = new Node(50);
root->left = new Node(45);
root->right = new Node(60);
cout << "In Build Function\n";
cout << root << " " << root->data << endl;
cout << root->left << " " << root->left->data << endl;
cout << root->right << " " << root->right->data << endl;
return root;
}
void inorder(Node *root, vector<Node *> &A)
{
if (root == NULL)
return;
inorder((root)->left, A);
// free(root->left);
A.push_back(root);
cout << root << " " << root->data << endl;
inorder(root->right, A);
// free(root->right);
}
void print(vector<Node *> &A)
{
cout << "\nprint in function\n";
for (int i = 0; i < A.size(); i++)
cout << A[i] << " " << A[i]->data << endl;
cout << endl;
}
int main()
{
Node *root = build();
cout << "\nIn Main Function\n";
cout << root << " " << root->data << endl;
cout << root->left << " " << root->left->data << endl;
cout << root->right << " " << root->right->data << endl;
vector<Node *> A;
cout << "\nIn inorder Function\n";
inorder(root, A);
print(A);
cout << "\nIn Main Function\n";
cout << root << " " << root->data << endl;
cout << root->left << " " << root->left->data << endl;
cout << root->right << " " << root->right->data << endl;
}