Question
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.
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 BtST
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 BtST() { }
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
}
Current output, L 11 P 10 M 9 X 7 H S R 3 A 8 12 size mpty at does not contain A st doe not contain B St does not conta1n C gt does nat contain D at does not contain E st doe not contain F at does not cant G st does not contain H at does not contain I st doe not contain J su does not contain K st does not contain L at does not contain M at does not contain N s does not contain st does not contain P at does not contain at does not contain R St does not contain S st does not contain T gt does nat contain U st does not contain V St does not contain St does not conta1n X gt does nat contain Y et does not contain 2 Correct output, L 11 P 10 M 9 X 7 H 5. C 4 R 3 A 8 E 12 5 0 st is not empty st does contain A st does not contain B st does contai st does not contain D st does contain E st does not contain F st does not contain G st does contain H st does not contain I st does not contain J st does not contain K st does contain L st does contai n M st does not contain N st does not contain 0 st does contain P st does not contain Q st does contain R st does contain 5 st does not contain T st does not contain U st does not contain V st does not contai n W st does contai st does not contain Y st does not contain Z
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started