package sort;
/**
* Informatik II - SS2007 <br>
* Uebungsserie 2, Aufgabe 3 <br>
* Template for class ConvertTree.java <br>
*
* @author Silvia Santini
*/
public class ConvertTree {
char[] tree; //tree is a reference to an rray of char
/**
* Constructor
**/
ConvertTree(char[] a) {
tree = a;
}
// param i: position in array
// param j: current indention-level
void indent( int i, int j ) {
/* if(i==null)
{
return;
//break condition...) return;
}
*/
if(i != null && 2*i != null)
indent( 2*i ,j+1);
if(i != null && 2*i == null && 2*i+1 != null)
indent( 2*i+1 ,j+1);
// Print a space for each new tree-level
for( int n=0; n<j; n++ ) {
System.out.print( " " );
}
System.out.println(tree[i]);
//recursive calls
/* indent( 2*i ,j+1);
......*/
}
/**
* Give the programm the tree's array-representation as a
* single string argument.
* If your representation includes space characters,
* then include quotes.
* Example:
*
* java CovertTree $"123 67"$
*
* Test the programm with the following inputs (a missing node
* is represented by a space character):
*
* "1234567"
* "1 3 67"
* "AB D H P"
* "A C G O"
**/
public static void main( String args[] ) {
if( args.length == 0 || args.length > 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
String input = " " + args[0];
//the method toCharArray converts a string in an array of
//characters
ConvertTree ct = new ConvertTree(input.toCharArray());
// ct is an instance of the CovertTree class
// which is initialised with the given array
// representation
ct.indent(1,0);
}
}