Write a java program which generates a binary tree in two ways: 1. Array-based 2. Reference-based Show transcribed image text Write a java program which generates a binary tree in two ways: 1. Array-based 2. Reference-based
Solution
write a java program which generates a binary tree in arraybased:-
import java.util.*;
import java.lang.*;
import java.io.*;
class Tree {
public static void main(String[]args)
{
Array_imp obj =new Array_imp();
obj.Root(“A”);
// obj.set_Left(“B”,0);
obj.set_Right(“C”,0);
obj.set_Left(“D”,1);
obj.set_Right(“E”,1);
obj.set_Left(“F”,2);
obj.print_Tree();
}
}
class Array_imp {
static int root = 0;
static String[] str = newString[10];
/*create root*/
public void Root(String key)
{
str[0] =key;
}
/*create left son of root*/
public void set_Left(String