(oris ne in the program to match the diagram at the bottom of the page This time
ID: 3756737 • Letter: #
Question
(oris ne in the program to match the diagram at the bottom of the page This time, it is the horizontal group of boxes that denotes an array object. Not all blank lines need to be used. int N-some positive integer (N 2 1) IntList LA new IntList [N] / arraycopy (FROM_ARR, FROM_INDEX, TO_ARR, TO_INDEX, LENGTH) import static java.lang.System.arraycopy: public class IntList First element of list, public int head; Remaining elements of list. / public IntList tail; A List with head HEADO and tail TAILO. public IntList(int heado IntList tai10) head heado; tail tai1o; ) /A List with null tail, and head 0. / public IntList() { this(o, null); } Returns a ne IntList containing the ints in ARGS. / public static IntList list (Integer.. args) / Implenentation not shoun Returns true iff L (together with the itens reachable from it) is an IntList with the same itema as thia list in the same order &Override public boolean equals(Object L) f / Implenentation not shouwn **Return the length of the non-circular list headed by L. 0verride public int aize) ( / Implementation not shownExplanation / Answer
I am not completely able to understand the question, still on the basis of whatever is possible, I will try to answer. Please repost in case something else is expected with the question.
Problem Statement states about concept of
Let's take these one by one :-
arraycopy() method is present in java.lang.System library of Java. This method copies a source array to destination array as per the positions provided (the elements are over-written in destination array) and the length that how many indexes needs to be copied.
The method definition for arraycopy(Object source_array, int source_position, Object destination_array, int destination_position, int length)
Sample implementation :-
public static void main(String[] args)
{
int source_array[] = { 1, 3, 5, 7, 9, 11 };
int destination_array[] = { 2 ,4 ,6 ,8 ,10 ,12 };
int source_pos, dest_pos, length;
source_pos = 3; destPos = 4;
length = 2;
// Use of arraycopy() method
System.arraycopy(source_array, source_pos, destination_array,
dest_pos, length);
// Print elements of destination after arraycopy method
for (int i = 0; i < destination_array.length; i++)
System.out.print(destination_array[i] + " ");
}
Over-riding the methods equals and size, simply maintain a global int variable and everytime an integer is added, increment by 1, return the global variable from size() methods ,
public class IntList {
int head;
IntList tail;
int actSize = 0;
public IntList(int head0, IntList tail0) {
head = head0;
tail = tail0;
}
public IntList() {
this(0,null);
}
public IntList list(Integer ...args){
IntList list = new IntList(args[1], null);
//increase the size based on integers provided to add
actSize++;
return list;
}
@Override
public boolean equals(Object L){
return this == null ? L == null : this.equals(L);
}
public int size(){
return actSize;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.