void walk_tree_vlr(TreeNode* root)
{
if (root == NULL)
return;
cout << root->value << " ";
walk_tree_vlr(root->left);
walk_tree_vlr(root->right);
}
int main()
{
int cur;
int N = 0;
while(cin >> cur)
{
TreeNode* newTree = new TreeNode(cur);
if (N == 0)
{
N++;
root = new TreeNode(cur);
curTree = root;
continue;
}
curTree = root;
while (curTree != NULL)
{
if (cur > curTree->value)
{
if (curTree->right == NULL)
{
curTree->right = newTree;
break;
}
else
{
curTree = curTree->right;
}
}
else
{
if (curTree->left == NULL)
{
curTree->left = newTree;
break;
}
else
{
curTree = curTree->left;
}
}
}
if (cin.get() == '\n')
{
break;
}
}
walk_tree_vlr(root);
}