// sorting integers by binary tree 
// using reference
// and constructor

#include <iostream>^M
#include <new>

using namespace std;

void *operator new( size_t sz, int i, double d, const char *s)^M
{^M
    std::cerr << "node::new" << ", " << i << ", " ^M
              << d << ", " << s << std::endl;^M
    return malloc(sz);^M
}^M
void operator delete( void *p, int i, double d, const char *s)^M
{^M
    std::cerr << "::delete" << std::endl;^M
    // return free(p);^M
    free(p);^M
}^M
^M
struct node
{
         node( int v);
    void print() const;
^M
    void *operator new( size_t sz, int i, double d, const char *s) ^M
    { ^M
        std::cerr << "::new" << ", " << i << ", " ^M
                  << d << ", " << s << std::endl;^M
        return ::operator new( sz, i, d, s);^M
    }^M
    void  operator delete(void *p)^M
    { ^M
        std::cerr << "node::delete" << std::endl;^M
        ::operator delete(p);^M
    }
^M
    int   val;
    node *left;
    node *right;
};
node::node( int v)        // the constructor
{
    left = right = 0;
    val = v;
}
void node::print() const    // a const member function
{
    cout << val << " "; 
}

void insert( node *&r, int v);  // insert into (sub)tree
void print( node *r);           // print (sub)tree

int main()
{
    node *root = 0;
    int   i;
    
    while ( cin >> i )
    {
        insert( root, i);
    }
    print( root);
    return 0;
}
void print( node *r)
{
    if ( r )
    {
        print( r->left);
        r->print();
        print( r->right);
    }
}
void insert( node *&r, int v)
{
    if ( r )
    {
        insert( v < r->val ? r->left : r->right, v);
    }
    else
    {
        r = new(4, 3.14, "Hello") node(v);
    }
}