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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!