#include <stdlib.h>
#include <stdio.h>

typedef struct node{
	int data;
	node *left;
	node *right;
	node *parent;
} node;

void InorderTraversal(struct node *root){
	if(root != NULL){
		InorderTraversal(root->left);
		printf("%d ", root->data);
		InorderTraversal(root->right);
	}
}

void TreeInsert(struct node *root, struct node *z){
	struct node *y = NULL;
	struct node *x = root;

	while(x != NULL){
		y = x;
		if(z->data < x->data)
			x = x->left;
		else
			x = x->right;
	}
	z->parent = y;
	if(y == NULL)
		root = z;
	else{
		if(z->data < y->data)
			y->left = z;
		else
			y->right = z;
	}
}

int main(void) {
	node *tree;
	node *p;

	tree = NULL;
	for(int i = 0; i < 10; i++){
		p = (struct node *)malloc(sizeof(struct node));
		p->data = i;
		p->left = NULL;
		p->right = NULL;
		TreeInsert(tree, p);
	}

	InorderTraversal(tree);
	return 0;
}
