public class PrintTrees 
//Overton's algorithm to print trees
{		
    public static void main(String[] abc)
	{
		System.out.println("Type your data");
		ConsoleReader kbd = new ConsoleReader();
		String line = kbd.readLine();
		Tree2 tree = new Tree2();
		tree.binary(line);
		tree.printInfix();
		System.out.println();		
		Tree2 t = new Tree2();
		t.copyTree(tree);
		t.printInfix();
		System.out.println();		
		Tree0 tr = new Tree0();
		tr.init();
		tr.display();
		tr.tree2pic(t);
		tr.display();
	}								
}

class Tree0 extends Tree2
//In class Tree2, class Node must be made public to enable inheritance
//The URL of the Tree2 class is defined in:
//http://cs.nyu.edu/courses/spring01/V22.0102-002/Trys.java  
{
	final int rowMax = 8, colMax = 75;
	final char blank = '.';
	char[][] picture = new char[rowMax][colMax];
	
	
	void leftDiag(Node t, int row, int col, int width)
	{
		col = col - width/8;
		picture[row+1][ col] = '/';
	}
	
	void rightDiag(Node t, int row, int col, int width)
	{
		col = col + width/8;
		picture[row+1][ col] = '\\';
	}
	
	void tree2pic(Tree t)
	{
		tree2pic(t.root, 1, colMax/2, colMax);
	}
	
	void tree2pic(Node t, int row, int col, int width)
	{
		int subWidth;
		if(t != null && row <= rowMax)
		{
			picture[row][ col] = t.data;
			subWidth = width/2;
			leftDiag(t, row, col, width);
			tree2pic(t.left, row + 2, col - subWidth/2, subWidth);
			rightDiag(t, row, col, width);
			tree2pic(t.right, row + 2, col + subWidth/2, subWidth);
		}
	}
	
	void init()
	{		
		for( int r = 0; r < rowMax; r++)
		{
			for(int c = 0; c < colMax; c++)
			{
				 picture[r][c] = blank;
			}
		}
	}	
	
	void display()
	{		
		for( int r = 0; r < rowMax; r++)
		{
			for(int c = 0; c < colMax; c++)
			{
				System.out.print(picture[r][c]);
			}
			System.out.println();
		}
	}	
}

