-public class Foo {
+public class Tree {
+ Node root;
+}
+
+public class Node {
int z;
+ Node left;
+ Node right;
+ Node() {
+ z = 1;
+ left = null;
+ right = null;
+ }
}
+
public class Test {
static public void main( String args[] ) {
- int m = 2;
int n = 3;
-
- Foo[] a;
- Foo b;
-
- Foo[][] top = new Foo[m][];
- for( int i = 0; i < m; ++i ) {
- a = getArray( n );
- for( int j = 0; j < n; ++j ) {
- b = getFoo();
- a[j] = b;
- }
- top[i] = a;
+ Tree[] trees = new Tree[n];
+ for( int i = 0; i < n; ++i ) {
+ trees[i] = getTree();
+ build( trees[i] );
}
- // every Foo is reachable from only one Foo array
+ // every Node is reachable from only one Tree
gendefreach z0;
genreach z0;
- // resize array...
- //Foo[] b = getArray( n + 1 );
- //Foo[] notused = getArray( 1 );
- //b[0] = getFoo();
- //for( int j = 0; j < n; ++j ) {
- // b[j+1] = a[j];
- //}
+ int total = 0;
+ for( int i = 0; i < n; ++i ) {
+ Tree t = trees[i];
- // after array resize?
- gendefreach z1;
- genreach z1;
+ // select a tree
+ gendefreach z1;
+ genreach z1;
- // use info to keep compiler from optimizing anything away
- int total = 0;
- for( int i = 0; i < m; ++i ) {
- for( int j = 0; j < n; ++j ) {
- total += top[i][j].z;
- }
+ sillyRemove( t.root );
+
+ // after remove
+ gendefreach z2;
+ genreach z2;
+
+ total += t.root.z;
}
+
System.out.println( " "+total );
}
+
+ static public Tree getTree() {
+ return disjoint jupiter new Tree();
+ }
- static public Foo[] getArray( int n ) {
- return disjoint jupiter new Foo[n];
+ static public Node getNode() {
+ return new Node();
}
- static public Foo getFoo() {
- Foo f = new Foo();
- f.z = 1;
- return f;
+ static public void build( Tree t ) {
+ t.root = getNode();
+ t.root.left = getNode();
+ t.root.left.left = getNode();
+ t.root.left.right = getNode();
+ t.root.right = getNode();
+ t.root.right.left = getNode();
+ t.root.right.right = getNode();
}
+ static public void sillyRemove( Node n ) {
+ if( n != null &&
+ n.left != null &&
+ n.left.left != null ) {
+ n.left = n.left.left;
+ }
+ }
}