Write Java Program Generates Binary Tree Two Ways 1 Array Based 2 Reference Based Q37149241

Write a java program which generates a binary tree in two ways: 1. Array-based 2. Reference-based

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

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.