A utility function to allocate a new node
function newNode ( data ) { var newNode = new Node ( ) ; newNode . data = data ; newNode . left = null ; newNode . right = null ; return newNode ; } function rec ( root ) {