// Tree.java public class Tree { private static class TreeNode { Node filhos; int val; TreeNode( int info ) { val = info; filhos = null; } } private static class Node { TreeNode child; Node next; Node( TreeNode n ) { child = n; next = null; } } private TreeNode root; public Tree( int n ) { root = new TreeNode( n ); } private Node append( Node n, TreeNode tnode ) { if ( n == null ) return new Node( tnode ); n.next = append( n.next, tnode ); return n; } private TreeNode find( TreeNode n, int val ) { if ( n == null ) return null; if ( n.val == val ) return n; Node f = n.filhos; while ( f != null ) { TreeNode aux = find( f.child, val ); if ( aux != null ) return aux; f = f.next; } return null; } public void insert( int p, int f ) { TreeNode n = find( root, p ); if ( n == null ) return; n.filhos = append( n.filhos, new TreeNode( f ) ); } private void print( TreeNode n ) { System.out.println("print()"); } public void print( ) { print ( root ); } }