Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

hello i.m suppose to write binary tree with using java code. I keep getting 2 er

ID: 3550550 • Letter: H

Question


hello


i.m suppose  to write binary tree with using java code.


I keep getting  2 errors at the point what i marked.


could you tell me that how can i fix my errors?







package binTree;

import java.util.Random;

public class BinTree {

public static void main(String[] args)

{BinTree tree= new BinTree();

int value;

Random randomNumber = new Random();

System.out.println("building binary tree...");

for(int i=1; i<=10;i++)

{

value= randomNumber.nextInt(100);

System.out.printf("%d", value);

// tree.insertNode (value);

}

System.out.println(" Inorder traversal");

// tree.treeWalk();

}


}


class Binary

{

private Binary leftNode, rightNode;

private int key;

public Binary(int key)

{

this.key=key;

}


public void insertNode(int value)

{

if(key > value)

{

if(leftNode !=null)

{

leftNode.insertNode(value);

}

else

{

leftNode= new Binary(value);

}

}

if(key<value)

{

if(rightNode != null)

{

rightNode.insertNode(value);

}

else

{

rightNode= new Binary(value);

}

}

}

public void treeWalk()

{

if(leftNode != null)

leftNode.treeWalk();

     System.out.println(key + "");

if(rightNode !=null)

rightNode.treeWalk();

}

Explanation / Answer


hi this is the full implementation of your assignment please have a look and run this program

if found helpful then please rate


public class BinTree {

public BinTree(Object item) {

root = new TreeNode(item, null, null);

}

private BinTree(TreeNode t) {

root = t;

}

public Object getRootData() {

return root.item;

}

public void setRootData(Object newItem) {

root.item = newItem;

}


public boolean addLeft(Object newItem) {

if (root.left == null) {

root.left = new TreeNode(newItem, null, null);

return true;

}

else {

return false;

}

}

public boolean addRight(Object newItem) {

if (root.right == null) {

root.right = new TreeNode(newItem, null, null);

return true;

}

else {

return false;

}

}