Question: Please fix the error with this code due soon!!! Help fixing this error: .BST.java:164: error: method setLeft in class Node cannot be applied to given

Please fix the error with this code due soon!!!

Help fixing this error:

.\BST.java:164: error: method setLeft in class Node cannot be applied to given types; node.setLeft() = successor(node.getLeft(), key); ^ required: Node found: no arguments reason: actual and formal argument lists differ in length .\BST.java:167: error: method setRight in class Node cannot be applied to given types; node.setRight() = successor(node.getRight(), key); ^ required: Node found: no arguments reason: actual and formal argument lists differ in length

Heres the code:

public class BST { public Node root; private String result; public BST() { root = null; } public void insert(int value) { if (root == null) { root = new Node(value); } else { Node cur = root; Node parent; while (true) { parent = cur; if (value < cur.getData()) { cur = cur.getLeft(); if (cur == null) { parent.setLeft(new Node(value)); return; } } else { cur = cur.getRight(); if (cur == null) { parent.setRight(new Node(value)); return; } } } } } // The search() method: public boolean search(int value){ if(root == null){ return false; } else{ Node cur = root; while(cur.getData() != value){ if(value < cur.getData()){ cur = cur.getLeft(); } else{ cur = cur.getRight(); } } if(cur.getData() == value){ return true; } else{ return false; } } } // The min() method public int min(){ Node cur = root; while(cur.getLeft() != null){ cur = cur.getLeft(); } if(root==null){ return -1; } return cur.getData(); } // The max method public int max(){ Node cur = root; while(cur.getRight()!=null){ cur = cur.getRight(); } if(root==null){ return -1; } return cur.getData(); } // The private inOrder() method private String inOrder(Node node){ String result=""; if(node != null){ result += inOrder(node.getLeft()); result += node.getData() + " "; result += inOrder(node.getRight()); return result; } else{ return ""; } } public String inorder(){ return inOrder(root); } // The PreOrder() method private String PreOrder(Node cur){ String str=""; if(cur != null){ str += cur.getData() + " "; str += PreOrder(cur.getLeft()); str += PreOrder(cur.getRight()); return str; } else{ return ""; } } // The preorder() method public String preorder(){ String val = PreOrder(root); return val; } // The postOrder() method private String postOrder(Node node){ String s=""; if(node!=null){ s += postOrder(node.getLeft()); s += postOrder(node.getRight()); s += node.getData() + " "; return s; } else{ return ""; } } // The postorder method public String postorder(){ return postOrder(root); } // successor function private int successor(Node node){ node = node.getRight(); while(node.getLeft() != null){ node = node.getLeft(); } return node.getData(); } // predecessor function private int predecessor(Node node){ node = node.getLeft(); while(node.getRight()!=null){ node = node.getRight(); } return node.getData(); } // delete() method // successor(node) function private Node successor(Node node, int key){ if(node == null){ return node; } if(key < node.getData()){ node.setLeft() = successor(node.getLeft(), key); } else if(key > node.getData()){ node.setRight() = successor(node.getRight(), key); } else{ if(node.getLeft()==null){ return node.getRight(); } else if(node.getRight()==null){ return node.getLeft(); } node.setData(minVal(node.getRight())); node.setRight(successor(node.getRight(), node.getData())); } return node; } // minVal() function private int minVal(Node node){ int m = node.getData(); while(node.getLeft() != null){ m = node.getLeft().getData(); node = node.getLeft(); } return m; } // delete() method public void delete(int value){ Node node = successor(node, value); } } class Node { private Node left; private Node right; private int data; public Node(int data) { left = right = null; this.data = data; } public int getData() { return data; } public Node getLeft() { return left; } public Node getRight() { return right; } public void setLeft(Node left) { this.left = left; } public void setRight(Node right) { this.right = right; } public void setData(int data) { this.data = data; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!