function to print tree