If the lists have the same number of elements order by how


PLease help You need this in java please also explain what how the comparable interface works and also how a compareTo method works

Have the AList class implement the Comparable interface. Write the compareTo method to order lists this way:

First by size: a list that has fewer elements is smaller

Second, if the lists have the same number of elements: order by how many elements in the matching index of the other list are smaller; the list with more smaller elements in the matching position is smaller (see the examples below)

Note, to test your AList class, use these class and method headers:

public class AList implements ListInterface, Comparable>

public int compareTo(AList otherList)

You also need to change the lines in the constructor and toArray methods from using Object to using Comparable:

T[] tempList = (T[]) new Comparable[initialCapacity + 1];

T[] result = (T[]) new Comparable[numberOfEntries]; // Unchecked cast

Example:

List A: 1, 5, 6, 8, 10

List B: 2, 4, 3, 9, 7

In this example, List B is smaller because 3/5 elements in List B are less than their matching element in List A (4 < 5, 3 < 6, and 7 < 10).

List A: 1, 3, 5, 7, 10

List B: 2, 4, 3, 9, 7

In this example, List A is smaller because 3/5 elements in List A are less than their matching element in List B 1 < 2, 3 < 4, and 7 < 9).

List A: 1, 2, 3, 10, 9

List B: 2, 4, 3, 9, 7

In this example, neither is smaller because each has 2/5 elements smaller than their matching element in the other list.

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: If the lists have the same number of elements order by how
Reference No:- TGS02889342

Expected delivery within 24 Hours