Question
(URGENT) JAVA: Return an exact copy of the set public class Set { private int SIZE = 20; // length of the array private int
(URGENT) JAVA: Return an exact copy of the set
public class Set {
private int SIZE = 20; // length of the array
private int[] S ; // array holding the set
private int next; // pointer to next available slot in array
//public Set() -- Default constructor; Constructs this set as an instance of the empty set
public Set() {
// your code here
S = new int[SIZE];
}
//--------------------------------------------------------------------------------
/* public Set(int[] A) -- Construct this set consisting of exactly the elements of A (which,
you may assume, does not have duplicates); A can be of arbitrary
length (it may not be smaller than SIZE). (Hint: create an empty
set and use insert(...) to add the elements, which may trigger a
resize of the array.)
*/
public Set(int[] A) {
// your code here
if (A.length >= S.length) {
S = java.util.Arrays.copyOf(A, S.length);
next = 20;
} else {
next = A.length;
for (int i = 0; i < A.length; i++) {
S[i] = A[i];
}
}
}
//public Set clone() -- Return an exact copy of this set (hint: use the previous constructor).
public Set clone() {
// your code here
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