Question: * * * * I just need the java code for MySorts.java and Main.java * * * * * IList . java * public interface
I just need the java code for MySorts.java and Main.java
IListjava
public interface IList
Adds an element at the end of the list.
public void addT item;
Stores a new item at a specified index
Throws NoSuchElementException if index is out of bounds.
public void setint index, T item;
Inserts an element at the specified index
Throws NoSuchElementException if index is out of bounds.
public void insertint index, T item;
Removes the element at the specified index
Throws NoSuchElementException if index is out of bounds.
public void removeint index;
Returns the element at the specified index
Throws NoSuchElementException if index is out of bounds.
public T getint index;
Returns the size of the list.
@return the number of elements in the list
public int size;
MyArrayListjava
import java.util.ArrayList;
public class MyArrayList implements IList
private ArrayList list new ArrayList;
@Override
public void addT item
list.additem;
@Override
public int size
return list.size;
@Override
public T getint index
return list.getindex;
@Override
public void setint index, T item
list.setindex item;
@Override
public void insertint index, T item
list.addindex item;
@Override
public void removeint index
list.removeindex;
Additional Information
MySorts merge sort algorithm
the mergesort method will take a reference to an IList object as its only argument. This method will call the mergesortHelper method to do the actual work of sorting the list. This is the method that one would call to apply the quicksort algorithm to a list of values. By the time this method returns, the values in the argument IList should be sorted.
the mergesortHelper method is a recursive method that will implement the actual merge sort algorithm. The argument is a reference to the list of values that is to be sorted. this method will call the getLeftHalf and getRightHalf methods to divide a larger list, and call the merge method to merge two sorted sublists into one sorted list.
the getLeftHalf method will take as its argument, a reference to the list of values that is to be sorted. This method will return an IList that contains the first half of the list that was passed to it as an argument.
For examples:
given an IList named list, of these values getLeftHalflist would return an IList with these values ;
given an IList named list, of these values getLeftHalflist would return an IList with these values
Note that for lists with an odd number of values like the getLeftHalf method should return the smaller half of the list ie instead of
the getRightHalf method will take as its argument, a reference to the list of values that is to be sorted. This method will return an IList that contains the second half of the list that was passed to it as an argument.
For examples:
given an IList named list, of these values getRightHalflist would return an IList with these values ;
given an IList named list, of these values getRightHalflist would return an IList with these values
Note that for lists with an odd number of values like the getRightHalf method should return the larger half of the list ie instead of
the merge method will take two sorted lists as arguments. This method must create a new IList and merge the two argument lists into one sorted list that will be returned.
For examples:
given an IList named list of these values and an IList named list of these values mergelist list would return an IList with these values ;
given an IList named list of these values and an IList named list of these values mergelist list would return an IList with these values ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
