package psa.naloga1; public class Binarno { private NodeBinarno root; public boolean insert(int element){ if(search(element)){ return false; } root=insertNode(root,element); return true; } private NodeBinarno insertNode(NodeBinarno node,int element){ if(node==null){ NodeBinarno insertedNode=new NodeBinarno(element); return insertedNode; } if(elementnode.getKey()){ node.setRightChild(insertNode(node.getRightChild(),element)); } return node; } private NodeBinarno deleteNode(NodeBinarno node,int element){ if (node==null){ return node; } if(element node.getKey()) { node.setRightChild(deleteNode(node.getRightChild(),element)); }else{ if(node.getLeftChild()==null){ return node.getRightChild(); }else if(node.getRightChild()==null){ return node.getLeftChild(); } node.setKey(findMin(node.getRightChild())); node.setRightChild(deleteNode(node.getRightChild(),node.getKey())); } return node; } private int findMin(NodeBinarno node){ while(node.getLeftChild()!= null){ node=node.getLeftChild(); } return node.getKey(); } public boolean delete(int element) { if(search(element)){ root=deleteNode(root, element); return true; } return false; } private boolean searchNode(NodeBinarno node,int element){ if(node==null){ return false; } if(element==node.getKey()){ return true; } if(element < node.getKey()){ return searchNode(node.getLeftChild(),element); } else { return searchNode(node.getRightChild(),element); } } public boolean search(int element){ return searchNode(root,element); } public int getCounter() { return root != null?root.getCounter():null; } public void resetCounter() { if(root!= null) root.resetCounter(); } } package psa.naloga1; public class NodeBinarno { private static int counter; private int key; private NodeBinarno leftChild; private NodeBinarno rightChild; public NodeBinarno(int key){ this.key=key; this.leftChild=null; this.rightChild=null; } public NodeBinarno(int key,NodeBinarno left,NodeBinarno rightChild){ this.key= key; this.leftChild=left; this.rightChild=rightChild; } public NodeBinarno getLeftChild(){ return this.leftChild; } public void setLeftChild(NodeBinarno left){ this.leftChild=left; } public NodeBinarno getRightChild(){ return this.rightChild; } public void setRightChild(NodeBinarno right){ this.rightChild=right; } public int getKey(){ return this.key; } public void setKey(int key){ this.key=key; } public int compare(NodeBinarno node) { counter++; return node.key - this.key; } public int getCounter() { return counter; } public void resetCounter() { counter=0; } } public class NodeSeznam { private static int counter; private int key; private NodeSeznam next; public int compare(NodeSeznam node) { counter++; return node.key - this.key; } public NodeSeznam (int key, NodeSeznam next){ this.key = key; this.next = next; } public int getCounter() { return counter; } public void resetCounter() { counter = 0; } public NodeSeznam getNext() { return next; } public void setNext(NodeSeznam next) { this.next = next; } } package psa.naloga1; public class Seznam { private NodeSeznam head; public Seznam() { head = null; } public boolean insert(int element) { NodeSeznam insertedNode = new NodeSeznam(); insertedNode.key = element; if (head == null) { head = insertedNode; return true; } else { NodeSeznam pom = head; while (pom.getNext() != null) { pom = pom.getNext(); } pom.setNext(insertedNode); return true; } } public boolean delete(int element) { if (head == null) { return false; } if (head.key == element) { head = head.getNext(); return true; } NodeSeznam pom = head; while (pom.getNext() != null) { if (pom.getNext().key == element) { pom.setNext(pom.getNext().getNext()); return true; } pom = pom.getNext(); } return false; } public boolean search(int element) { if (head == null) { return false; } if (head.key == element) { return true; } NodeSeznam pom = head; while (pom.getNext() != null) { if (pom.getNext().key == element) { return true; } pom = pom.getNext(); } return false; } public int getCounter() { return head != null ? head.getCounter() : 0; } public void resetCounter() { if (head != null) { head.resetCounter(); } } } can you please try and correct the mistakes in my code because it did not pass the release tests but it passed all 6 public tests, and all 9 release tests should pass. the requirements to pass the release tests are shown on the image
package psa.naloga1;
public class Binarno {
private NodeBinarno root;
public boolean insert(int element){
if(search(element)){
return false;
}
root=insertNode(root,element);
return true;
}
private NodeBinarno insertNode(NodeBinarno node,int element){
if(node==null){
NodeBinarno insertedNode=new NodeBinarno(element);
return insertedNode;
}
if(element<node.getKey()){
node.setLeftChild(insertNode(node.getLeftChild(),element));
}else if(element>node.getKey()){
node.setRightChild(insertNode(node.getRightChild(),element));
}
return node;
}
private NodeBinarno deleteNode(NodeBinarno node,int element){
if (node==null){
return node;
}
if(element<node.getKey()){
node.setLeftChild(deleteNode(node.getLeftChild(), element));
} else if (element > node.getKey()) {
node.setRightChild(deleteNode(node.getRightChild(),element));
}else{
if(node.getLeftChild()==null){
return node.getRightChild();
}else if(node.getRightChild()==null){
return node.getLeftChild();
}
node.setKey(findMin(node.getRightChild()));
node.setRightChild(deleteNode(node.getRightChild(),node.getKey()));
}
return node;
}
private int findMin(NodeBinarno node){
while(node.getLeftChild()!= null){
node=node.getLeftChild();
}
return node.getKey();
}
public boolean delete(int element) {
if(search(element)){
root=deleteNode(root, element);
return true;
}
return false;
}
private boolean searchNode(NodeBinarno node,int element){
if(node==null){
return false;
}
if(element==node.getKey()){
return true;
}
if(element < node.getKey()){
return searchNode(node.getLeftChild(),element);
} else {
return searchNode(node.getRightChild(),element);
}
}
public boolean search(int element){
return searchNode(root,element);
}
public int getCounter() {
return root != null?root.getCounter():null;
}
public void resetCounter() {
if(root!= null)
root.resetCounter();
}
}
package psa.naloga1;
public class NodeBinarno {
private static int counter;
private int key;
private NodeBinarno leftChild;
private NodeBinarno rightChild;
public NodeBinarno(int key){
this.key=key;
this.leftChild=null;
this.rightChild=null;
}
public NodeBinarno(int key,NodeBinarno left,NodeBinarno rightChild){
this.key= key;
this.leftChild=left;
this.rightChild=rightChild;
}
public NodeBinarno getLeftChild(){
return this.leftChild;
}
public void setLeftChild(NodeBinarno left){
this.leftChild=left;
}
public NodeBinarno getRightChild(){
return this.rightChild;
}
public void setRightChild(NodeBinarno right){
this.rightChild=right;
}
public int getKey(){
return this.key;
}
public void setKey(int key){
this.key=key;
}
public int compare(NodeBinarno node) {
counter++;
return node.key - this.key;
}
public int getCounter() {
return counter;
}
public void resetCounter() {
counter=0;
}
}
public class NodeSeznam {
private static int counter;
private int key;
private NodeSeznam next;
public int compare(NodeSeznam node) {
counter++;
return node.key - this.key;
}
public NodeSeznam (int key, NodeSeznam next){
this.key = key;
this.next = next;
}
public int getCounter() {
return counter;
}
public void resetCounter() {
counter = 0;
}
public NodeSeznam getNext() {
return next;
}
public void setNext(NodeSeznam next) {
this.next = next;
}
}
package psa.naloga1;
public class Seznam {
private NodeSeznam head;
public Seznam() {
head = null;
}
public boolean insert(int element) {
NodeSeznam insertedNode = new NodeSeznam();
insertedNode.key = element;
if (head == null) {
head = insertedNode;
return true;
} else {
NodeSeznam pom = head;
while (pom.getNext() != null) {
pom = pom.getNext();
}
pom.setNext(insertedNode);
return true;
}
}
public boolean delete(int element) {
if (head == null) {
return false;
}
if (head.key == element) {
head = head.getNext();
return true;
}
NodeSeznam pom = head;
while (pom.getNext() != null) {
if (pom.getNext().key == element) {
pom.setNext(pom.getNext().getNext());
return true;
}
pom = pom.getNext();
}
return false;
}
public boolean search(int element) {
if (head == null) {
return false;
}
if (head.key == element) {
return true;
}
NodeSeznam pom = head;
while (pom.getNext() != null) {
if (pom.getNext().key == element) {
return true;
}
pom = pom.getNext();
}
return false;
}
public int getCounter() {
return head != null ? head.getCounter() : 0;
}
public void resetCounter() {
if (head != null) {
head.resetCounter();
}
}
}
can you please try and correct the mistakes in my code because it did not pass the release tests but it passed all 6 public tests, and all 9 release tests should pass. the requirements to pass the release tests are shown on the image
Step by step
Solved in 5 steps