Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
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( tree.length >= i || tree[i] == ' ' ) return;
//if(tree[i] != ' ' && tree[2*i] != ' ')
// if(i != ' ' && 2*i == ' ' && 2*i+1 != ' ')
// Print a space for each new tree-level
for( int n=0; n<j; n++ ) {
System.out.print( " " );
}
System.out.println(tree[i]);
indent( 2*i ,j+1);
indent( 2*i+1 ,j+1);
//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);
}
}
void indent( int i, int j ) {
int tl = tree.length;
if ( i >= tl || tree[i] == ' ' ) return;
// 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);
......*/
if ( (2*i) < tl && tree[2*i] != ' ' ) {
indent( 2*i ,j+1);
}
if ( (2*i+1) < tl && tree[2*i+1] != ' ' ) {
indent( 2*i+1 ,j+1);
}
}
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 );
}