Question: In java The provided ArrayListA.java file is missing two methods, sort and binarySearch. Complete each method so that it functions according to the commented description

In java

The provided ArrayListA.java file is missing two methods, sort and binarySearch. Complete each method so that it functions according to the commented description associated with each method.

sort implements either a selection or insertion sort to place the values of an ArrayList in ascending order.

binarySearch implements a binary search method that will take a given integer and return the index of where that value is in the ArrayList.

import java.util.ArrayList; public class ArrayListA { //ArrayList instance variable of Integers private ArrayList aList; /* Constructor which stores the given ArrayList * inside the ArrayListA object. */ public ArrayListA(ArrayList arr){ aList = arr; } /* A sorting method for the stored ArrayList * 7.6 has coded sorting algorithms, but please remember that * the given algorithms are for arrays, and would need to be * converted to use ArrayLists. You can use either Selection or * Insertion sort. */ public void sort(){ //to be implemented } /* A binary search method to return the index of a given value. * Will return -1 if the value is not found in the list. * 7.5 has coded searching algorithms, but please remember that * the given algorithms are for arrays, and would need to be * converted to use ArrayLists. */ public int binarySearch(int target){ //to be implemented return -1; } @Override public String toString(){ return "" + aList; } public static void main(String[] args) { // Create an ArrayList intList with the following values in // the order listed: 3, 1, 7, 5, -4, -29, 0, 2 /* The ArrayListA object will use the methods and store an * ArrayList. The expected output of printing q at this point * will be: * * [3, 1, 7, 5, -4, -29, 0, 2] */ ArrayListA q = new ArrayListA(intList); System.out.println(q); /* Use your binarySearch method to search for the value 0, * print it's index, remove it from the list, and print the * remaining list. * * Reminder: As aList and intList are both aliases, you can * remove an element from intList and it will affect what is * stored in q. * * The expected output will be: * * 2 * [-29, -4, 1, 2, 3, 5, 7] * */ } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!