Supposing you are writing your own ArrayList data structure with the following d
ID: 3825861 • Letter: S
Question
Supposing you are writing your own ArrayList data structure with the following declaration and partial code. Complete the code by adding an add (declaration given below) function making sure that if the ArrayList is already full you double it. Assume that you have a size() function that will return an Int value which is the total amount of element you have in that ArrayList at a given time. ****Given below ar two constructors that you may need in your add function. public class ArrayList {Object [] a; public ArrayList (int n) {a = new object [n] {for (int i = 0; iExplanation / Answer
public void add(Object x)
{
if (size() == a.length)
{
Object[] b = new Object[a.length*2];
for(int i = 0; i < a.length; i++)
{
b[i] = a[i];
}
a = b;
}
a[size()] = x;
// increase size;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.