/**
* Informatik II - FS2009
* Uebungsserie 2, Aufgabe 3
* Template for ConvertTree.java
*
* @author Philipp Bolliger
*/
public class ConvertTree {
char[] tree; //tree is a reference to an array of char
/**
* Initializes the class field 'tree' with the given char array.
*
* @param treeAsCharArray array representation of a binary tree
**/
ConvertTree(char[] treeAsCharArray) {
tree = treeAsCharArray;
}
/**
* Outputs the "indented" representation of the tree stored in the class field 'tree'.
*
* @param i position in array
* @param j current indentation-level
**/
void indent( int i, int j ) {
if( true /* insert break condition here!! */ ) return;
//Print a space for each new tree-level
for( int n=0; n 1 ) {
System.out.println( "Invalid input" );
System.exit( 1 );
}
// Prefix the input-string with a space character, so that
// the effective tree starts at index 1 (why is this "needed"?)
String input = " " + args[0];
//Create an instance of the class ConvertTree using the "new" keyword.
//The class field 'tree' is initialized with the tree array
//representation given as input parameter. The method toCharArray
//converts the input string in an array of characters.
ConvertTree ct = new ConvertTree(input.toCharArray());
//The 'indent' method is called on the ct instance of the ConvertTree class.
ct.indent(1,0);
}
}