Tree size and Maximum element in tree

package treeprobs;
class node1
{
node1 left;
node1 right;
int data;
public node1(int val)
{
data=val;
}
}
public class treeprobs
{
static int treesize(node1 root)
{
if(root==null)
return 0;
else
return (1+treesize(root.left)+treesize(root.right));
}

static int maxtree(node1 root)
{
if(root==null)
return 0;
else
return (1+treesize(root.left)+treesize(root.right));
}

public static void main(String arg[])
{
node1 a=new node1(1);
node1 b=new node1(2);
node1 c=new node1(3);
node1 d=new node1(4);
node1 e=new node1(5);
node1 f=new node1(6);
node1 g=new node1(7);

a.left=b;
a.right=c;
b.left=d;
b.right=e;
c.left=f;
c.right=g;
System.out.println(treesize(a));

}
}

Leave a Reply

Your email address will not be published. Required fields are marked *