#include<bits/stdc++.h>
using namespace std;
struct node{
int data;
node *left;
node *right;
};
node *newnode(int data){
node *temp = (node*) malloc(sizeof(node));
temp->data = data;
temp->left = temp->right = NULL;
return temp;
}
node *inserti(node *node, int data)
{
if(node == NULL)
return newnode(data);
else if(data < node->data)
node->left = inserti(node->left, data);
else if(data > node->data)
node->right = inserti(node->right, data);
return node;
}
void postorder(node *node){
if(node == NULL)
return;
postorder(node->left);
postorder(node->right);
cout << node->data <<endl;
}
int main()
{
int n;
int i = 1;
node *root = NULL;
while(cin >> n)
{
if(i == 1)
{
root = inserti(root, n);
i++;
}
else
inserti(root, n);
}
postorder(root);
return 0;
}
Comments
Post a Comment