In java I need help modifying the following sections size is

In java I need help modifying the following sections: size, isEmpy, contains. I am trying to do this without changing any declaration of any method. Thank you

public class MyST<Key, Value> {
private Node first;

  
private class Node {
private Key key;
private Value val;
private Node next;

public Node(Key key, Value val, Node next) {
this.key = key;
this.val = val;
this.next = next;
}
}


public MyST() {
}

public int size() {
       return 0;\\\\ ****
}

public boolean isEmpty() {
       return true; \\\\\\***
}


public boolean contains(Key key) {
if (key == null) throw new IllegalArgumentException(\"argument to contains() is null\");
       return false;\\\\\\\\ ***
}

public Value get(Key key) {
if (key == null) throw new IllegalArgumentException(\"argument to get() is null\");
for (Node x = first; x != null; x = x.next) {
if (key.equals(x.key))
return x.val;
}
return null;
}


public void put(Key key, Value val) {
if (key == null) throw new IllegalArgumentException(\"first argument to put() is null\");
if (val == null) {
delete(key);
return;
}

for (Node x = first; x != null; x = x.next) {
if (key.equals(x.key)) {
x.val = val;
return;
}
}
first = new Node(key, val, first);
}


public void delete(Key key) {
if (key == null) throw new IllegalArgumentException(\"argument to delete() is null\");
first = delete(first, key);
}

  
private Node delete(Node x, Key key) {
if (x == null) return null;
if (key.equals(x.key)) {
return x.next;
}
x.next = delete(x.next, key);
return x;
}

public Iterable<Key> keys() {
Queue<Key> queue = new Queue<Key>();
for (Node x = first; x != null; x = x.next)
queue.enqueue(x.key);
return queue;
}

}

Current output:

Correct output:

X 7 E 12 st dae et dae at doe dae et does at dae da- et doe st dae et doe ain Q

Solution

public MyST() {
}

public int size() {
       return 0;\\\\ ****
}

public boolean isEmpty() {
       return true; \\\\\\***
}


public boolean contains(Key key) {
if (key == null) throw new IllegalArgumentException(\"argument to contains() is null\");
       return false;\\\\\\\\ ***
}

public Value get(Key key) {
if (key == null) throw new IllegalArgumentException(\"argument to get() is null\");
for (Node x = first; x != null; x = x.next) {
if (key.equals(x.key))
return x.val;
}
return null;
}


public void put(Key key, Value val) {
if (key == null) throw new IllegalArgumentException(\"first argument to put() is null\");
if (val == null) {
delete(key);
return;
}

for (Node x = first; x != null; x = x.next) {
if (key.equals(x.key)) {
x.val = val;
return;
}
}
first = new Node(key, val, first);
}


public void delete(Key key) {
if (key == null) throw new IllegalArgumentException(\"argument to delete() is null\");
first = delete(first, key);
}

  
private Node delete(Node x, Key key) {
if (x == null) return null;
if (key.equals(x.key)) {
return x.next;
}
x.next = delete(x.next, key);
return x;
}

public Iterable<Key> keys() {
Queue<Key> queue = new Queue<Key>();
for (Node x = first; x != null; x = x.next)
queue.enqueue(x.key);
return queue;
}

}

In java I need help modifying the following sections: size, isEmpy, contains. I am trying to do this without changing any declaration of any method. Thank you p
In java I need help modifying the following sections: size, isEmpy, contains. I am trying to do this without changing any declaration of any method. Thank you p
In java I need help modifying the following sections: size, isEmpy, contains. I am trying to do this without changing any declaration of any method. Thank you p

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site