#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>

using namespace std;

struct school
{
int key;
school  *p_right;
school *p_left;
};

school *locale(school *NCT,  int key)
{
if (key < NCT->key)
{
	if (NCT->p_left == NULL)
		return NCT;
	else
		return locale(NCT->p_left, key);
}
else
{
	if (NCT->p_right == NULL)
		return NCT;
	else
		return locale(NCT->p_right,key);
}
}

void add (school *site, int key)
{
	school *newstu = new school;
	newstu->key = key;
	if (key > site->key)
		site->p_right = newstu;
	else
		site->p_left = newstu;
}

void generate(school *NCT, int n)
{
int key;
for (int i = 0; i<n;i++)
{
	key = rand()%100;
	school *site = locale(NCT, key);
	add(site, key);
}
}

sortschoolout(school *NCT)
{
if(NCT->p_right == NULL && NCT->p_left == NULL)
	cout<<NCT->key;
else if(NCT->p_right == NULL)
{
	sortschoolout(NCT->p_left);
	cout<<NCT->key;
}
else if(NCT->p_left == NULL)
{
	sortschoolout(NCT->p_right);
	cout<<NCT->key;
}
else
{
	sortschoolout(NCT->p_left);
	cout<<NCT->key;
	sortschoolout(NCT->p_right);
}
}

main()
{
school *NCT = NULL;
srand(time(NULL));
generate(NCT,10);
sortschoolout(NCT);
}
