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

icon
Related questions
Question

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

PUBLIC 4 passed 1
PUBLIC 5 passed
1
PUBLIC 6 passed 1
RELEASE 1 failed
1
RELEASE 2 failed
RELEASE 3 failed
RELEASE 4
RELEASE 5 failed
RELEASE 6 failed
failed
RELEASE 7 failed
RELEASE 8
RELEASE 9
13°C
Mostly cloudy
failed
failed
1
1
1
1 testSeznamSearchPoBrisanjuSteviloKorakovNatacno
1
1
testBinarnolskanje Uspesno
testBinarnoIskanje Neuspesno
1
testBinarnoBrisanje
testSeznamSearchSteviloKorakovNatacno
testSeznamSearchSteviloKorakovPriblizno
You received 6/6 points for public test cases.
testSeznam SearchPoBrisanjuSteviloKorakovPriblizno
1 testBinarnoSearchPoBrisanjuSteviloKorakovNatancno
testBinarnoSearchSteviloKorakovNatancno
testBinarnoSearchSteviloKorakovPriblizno
testBinarno SearchPoBrisanjuSteviloKorakovPriblizno
testBinarnoSearchSteviloKorakov WorstCase
| PASSED
PASSED
PASSED
Q Search
junit.framework. Assertion Failed Error: expected: <23> but was:<24>
at psa.naloga1.ReleaseTests.testSeznamSearchStevilokorakovNatacno (ReleaseTests.java:47)
junit.framework. Assertion FailedError
at psa.naloga1. ReleaseTests.testSeznamSearchStevilokorakov Priblizno (Release Tests.java:139)
junit.framework. AssertionFailed Error: expected: <20> but was:<21>
at psa.naloga1. ReleaseTests.testSeznamSearchPoBrisanjuStevilokorakovNatacno (Release Tests.java:172)
junit.framework. Assertion Failed Error
at psa.naloga1. Release Tests.testSeznam Search PoBrisanjuStevilokorakov Priblizno (ReleaseTests.java:271)
junit.framework. AssertionFailed Error: expected: <8> but was:<0>
at psa. naloga1. ReleaseTests.testBinarnoSearchStevilokorakovNatancno (ReleaseTests.java:301)
junit.framework. Assertion FailedError
at psa. naloga1. Release Tests.testBinarnoSearchStevilokorakovPriblizno (Release Tests.java:362)
junit.framework. AssertionFailed Error: expected: <6> but was: <0>
at psa. naloga1. ReleaseTests.testBinarnoSearchPoBrisanjuStevilokorakovNatancno (Release Tests.java:430)
junit.framework. Assertion Failed Error
at psa.naloga1. ReleaseTests.testBinarnoSearchPoBrisanjuStevilokorakovPriblizno (ReleaseTests.java:498)
junit.framework. AssertionFailed Error: expected: <40> but was:<0>
at psa.naloga1. ReleaseTests.testBinarnoSearchStevilokorakovWorstCase (Release Tests.java:540)
H
и
ENG
1:13 AM
11/7/2023
Transcribed Image Text:PUBLIC 4 passed 1 PUBLIC 5 passed 1 PUBLIC 6 passed 1 RELEASE 1 failed 1 RELEASE 2 failed RELEASE 3 failed RELEASE 4 RELEASE 5 failed RELEASE 6 failed failed RELEASE 7 failed RELEASE 8 RELEASE 9 13°C Mostly cloudy failed failed 1 1 1 1 testSeznamSearchPoBrisanjuSteviloKorakovNatacno 1 1 testBinarnolskanje Uspesno testBinarnoIskanje Neuspesno 1 testBinarnoBrisanje testSeznamSearchSteviloKorakovNatacno testSeznamSearchSteviloKorakovPriblizno You received 6/6 points for public test cases. testSeznam SearchPoBrisanjuSteviloKorakovPriblizno 1 testBinarnoSearchPoBrisanjuSteviloKorakovNatancno testBinarnoSearchSteviloKorakovNatancno testBinarnoSearchSteviloKorakovPriblizno testBinarno SearchPoBrisanjuSteviloKorakovPriblizno testBinarnoSearchSteviloKorakov WorstCase | PASSED PASSED PASSED Q Search junit.framework. Assertion Failed Error: expected: <23> but was:<24> at psa.naloga1.ReleaseTests.testSeznamSearchStevilokorakovNatacno (ReleaseTests.java:47) junit.framework. Assertion FailedError at psa.naloga1. ReleaseTests.testSeznamSearchStevilokorakov Priblizno (Release Tests.java:139) junit.framework. AssertionFailed Error: expected: <20> but was:<21> at psa.naloga1. ReleaseTests.testSeznamSearchPoBrisanjuStevilokorakovNatacno (Release Tests.java:172) junit.framework. Assertion Failed Error at psa.naloga1. Release Tests.testSeznam Search PoBrisanjuStevilokorakov Priblizno (ReleaseTests.java:271) junit.framework. AssertionFailed Error: expected: <8> but was:<0> at psa. naloga1. ReleaseTests.testBinarnoSearchStevilokorakovNatancno (ReleaseTests.java:301) junit.framework. Assertion FailedError at psa. naloga1. Release Tests.testBinarnoSearchStevilokorakovPriblizno (Release Tests.java:362) junit.framework. AssertionFailed Error: expected: <6> but was: <0> at psa. naloga1. ReleaseTests.testBinarnoSearchPoBrisanjuStevilokorakovNatancno (Release Tests.java:430) junit.framework. Assertion Failed Error at psa.naloga1. ReleaseTests.testBinarnoSearchPoBrisanjuStevilokorakovPriblizno (ReleaseTests.java:498) junit.framework. AssertionFailed Error: expected: <40> but was:<0> at psa.naloga1. ReleaseTests.testBinarnoSearchStevilokorakovWorstCase (Release Tests.java:540) H и ENG 1:13 AM 11/7/2023
Expert Solution
steps

Step by step

Solved in 5 steps

Blurred answer