Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How to fix this error .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

How to fix this error

.\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); ^ .\BST.java:116: error: right has private access in Node postorder(node.r

Heres the code: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_2

Step: 3

blur-text-image_3

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

=+7. What do NLP web services offer? Give examples.

Answered: 1 week ago