Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Define a class called ArrayList. It will be templated. The instance variable in

ID: 656652 • Letter: D

Question

Define a class called ArrayList. It will be templated.

The instance variable in the ArrayList will be a LinkedList containing the type.

You will implement the following functions on ArrayList:

int size(); // Determine how many elements are in the list.

int get(int index); // Retrieve the element at the location indicated by the parameter.

void set(int index,T t); // Set the element at the location indicated by the parameter.

bool contains(T t); // Determines if the list contains the paramter.

void add(T t); // Add an element to the end of the list.

bool remove(T t); // Remove all occurrences of an element from the list.

void addAll(ArrayList<T> list); // Add all elements from a list

void sort(); // Sort the elements in the list in ascending order using Selection Sort

void sort(bool); // Sort the elements in the list in descending order using Bubble Sort

T* toArray(int& size); // Convert the ArrayList to an array

The instance variable in the ArrayList will be a LinkedList. Each node in the LinkedList will contain an int which is the index and an elements of the type in the list.

After you have written the ArrayList, use it to write a function that will read from a file and print out the unique words found in the file in ascending order.

Explanation / Answer

arraylist is a kind of datastructure that deals with data and memory address which may be define as ArrayList is an completion of List , back by an array. All not obligatory operation counting adding, removing, and replacing elements are supported.

int size()

{

Set<String> itemIds = new HashSet<String>();

itemId = p.getItemId();

itemIds.add(itemId);

int uniqueItemIdCount = itemIds.size();

}

int get(int index)

{

public static void main (String []args)

{

ArrayList al = new ArrayList();

al.add("object");

al.add("object ");

al.add("object ");

al.add("object ");

System.out.println("Elements of list are : "+al);

System.out.println("Size of list = "+al.size());

for(int n=0;n<al.size();n++)

System.out.println("Element at the position " +i+"=" +al.get(n));

System.out.println("");

System.out.println("Element at the position "+(al.size()-al.size())+"="+al.get((al.size()-al.size())) );

System.out.println("Element at the last position " +(al.size()-1) +"="+al.get(al.size()-1));

}

}

void set(int index,T t);

void addAll(ArrayList<T> list);

public void addAll(int[] ai)

{

int numNew = ai.length;

ensureCapacity(size + numNew);

System.arraycopy(ai, 0, elements, size, numNew);

}

public void addAll(int index, int[] ai)

{

if (index < 0 || index > size)

throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);

int numNew = ai.length;

ensureCapacity(size + numNew);

int numMoved = size - index;

if (numMoved > 0) System.arraycopy(elements, index, elements, index + numNew, numMoved);

System.arraycopy(ai, 0, elements, index, numNew); size += numNew;

}

int remove(T t)

{

rangeCheck(index);

int oldValue = elements[index];

int numMoved = size - index - 1;

if (numMoved > 0) System.arraycopy(elements, index + 1, elements, index, numMoved);

return oldValue;

}

public X set(int index, X element)

{

rangeCheck(index);

XoldValue = elementData(index);

elementData[index] = element;

return oldValue;

}

public class sort implements Comparator<object>

{

public int compare(e1, e2)

{

return e1.getName().compareTo(e2.getName());

}

}

public static int[]

convertIntegers(List<Integer> integers)

{

int[] r = new int[integers.size()];

for (int x=0; x < r.length; i++)

{

r[i] = integers.get(i).intValue();

}

return r;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote