Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How to fix these errors in the code below PLEASE HELP THIS WAS DUE 10 MINUTES AGO .BST.java:71: error: left has private access in Node

How to fix these errors in the code below

PLEASE HELP THIS WAS DUE 10 MINUTES AGO

.\BST.java:71: error: left has private access in Node return findMin(node.left); ^ .\BST.java:80: error: right has private access in Node if (node.right == null) { ^ .\BST.java:81: error: data has private access in Node return node.data; ^ .\BST.java:83: error: right has private access in Node return findMax(node.right); ^ .\BST.java:93: error: left has private access in Node inorder(node.left, sb); ^ .\BST.java:94: error: data has private access in Node sb.append(node.data).append(" "); ^ .\BST.java:95: error: right has private access in Node inorder(node.right, sb); ^ .\BST.java:107: error: cannot find symbol sb.append(node.value).append(", "); ^ symbol: variable value location: variable node of type Node .\BST.java:108: error: left has private access in Node preorder(node.left, sb); ^ .\BST.java:109: error: right has private access in Node preorder(node.right, sb); ^ .\BST.java:115: error: left has private access in Node postorder(node.left, sb); ^ Heres the full code

class Node {

private Node left;

private Node right;

private int data;

public Node(int data) {

this.data = data;

left = null;

right = null;

}

public Node getLeft() {

return left;

}

public void setLeft(Node left) {

this.left = left;

}

public Node getRight() {

return right;

}

public void setRight(Node right) {

this.right = right;

}

public int getData() {

return data;

}

public void setData(int data) {

this.data = data;

}

}

class BST {

public Node root;

public BST() {

root = null;

}

public void insert(int value) {

root = insert(root, value);

}

private Node insert(Node node, int value) {

if (node == null) {

node = new Node(value);

} else if (value < node.data) {

node.left = insert(node.left, value);

} else {

node.right = insert(node.right, value);

}

return node;

}

public boolean search(int value) {

return search(root, value);

}

private boolean search(Node node, int value) {

if (node == null) {

return false;

} else if (node.data == value) {

return true;

} else if (value < node.data) {

return search(node.left, value);

} else {

return search(node.right, value);

}

}

public void delete(int value) {

root = delete(root, value);

}

private Node delete(Node node, int value) {

if (node == null) {

return node;

} else if (value < node.data) {

node.left = delete(node.left, value);

} else if (value > node.data) {

node.right = delete(node.right, value);

} else {

if (node.left == null) {

return node.right;

} else if (node.right == null) {

return node.left;

} else {

node.data = findMin(node.right);

node.right = delete(node.right, node.data);

}

}

return node;

}

public int findMin() {

return findMin(root);

}

private int findMin(Node node) {

if (node.left == null) {

return node.data;

} else {

return findMin(node.left);

}

}

public int findMax() {

return findMax(root);

}

private int findMax(Node node) {

if (node.right == null) {

return node.data;

} else {

return findMax(node.right);

}

}

public String inorder() {

return inorder(root, new StringBuilder()).toString();

}

private StringBuilder inorder(Node node, StringBuilder sb) {

if (node != null) {

inorder(node.left, sb);

sb.append(node.data).append(" ");

inorder(node.right, sb);

}

return sb;

}

public String preorder() {

return preorder(root, new StringBuilder()).toString();

}

private StringBuilder preorder(Node node, StringBuilder sb) {

if (node == null) return sb;

sb.append(node.value).append(", ");

preorder(node.left, sb);

preorder(node.right, sb);

return sb;

}

private StringBuilder postorder(Node node, StringBuilder sb) {

if (node != null) {

postorder(node.left, sb);

postorder(node.right, sb);

sb.append(node.data + " ");

}

return sb;

}

public String postorder() {

StringBuilder sb = new StringBuilder();

return postorder(root, sb).toString().trim();

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

13th Edition Global Edition

1292263350, 978-1292263359

Students also viewed these Databases questions