Question
Please help me code the following in JAVA Please read the task thoroughly, and include many COMMENTS so I can understand! Full points will be
Please help me code the following in JAVA
Please read the task thoroughly, and include many COMMENTS so I can understand!
Full points will be awarded, thanks in advance!
MyArrayList class:
import java.util.*;
import java.util.Comparator;
/**
* This class implements multiple sort algorithms to be used with ints, chars, and Stings.
* Bubble sort, Selection sort, and Insertion sorts are implemented here
*/
public class MyArrayList {
// instance data
protected int[] IntList;
protected char[] CharList;
protected String[] StringList;
// constructor will build all 3 arrays here
public MyArrayList() {
this.IntList = new int[10];
this.CharList = new char[10];
this.StringList = new String[5];
// fill all 3 arrays with data
for(int i = 0; i
IntList[i] = (int) (Math.random()*52);
}
// Populate char array
for(int i = 0; i
Random random = new Random();
CharList[i] = (char)(random.nextInt(26) + 'a');
}
// Populate String array
StringList[0] = "joe";
StringList[1] = "mark";
StringList[2] = "abbey";
StringList[3] = "tony";
StringList[4] = "kevin";
}
public int compareTo(MyArrayList other) {
// your code here
System.out.println("compareTo() is returning -1, array[0]
}
// your code here
System.out.println("compareTo() is returning 1, array[0] > other[0]");
}
else {
System.out.println("compareTo() is returning 0, array[0] != other[0] ");
// return a value here
}
}
public void intBubbleSort() {
// Implement your sort, call a helper swap method
}
public void CharBubbleSort() {
// Implement your sort, call a helper swap method
}
public void stringBubbleSort() {
// Implement your sort, call a helper swap method
}
public void swapInts(int[] intList, int j) {
// code for swapping ints
}
public void swapChars(char[] charList, int j) {
// code for swapping chars
}
public void swapStrings(String[] stringList, int j) {
// code for swapping Strings
}
//selection sort for ints
public void selectionSort() {
// Implement your sort, call swapSelection(int[] intList, int i, int nextMin)
}
//selection sort for Strings
public void stringSelectionSort() {
// Implement your sort, call swapSelectionStrings(String[] StringList, int i)
// and findSmallest(IntList, i, IntList.length) from your method
}
public void swapSelection(int[] intList, int i, int nextMin) {
// Your code here to swap int values
}
public void swapSelectionStrings(String[] StringList, int i) {
// Your code here to swap values
}
public int findSmallest(int[] arr, int begin, int end) {
//returns the index of the smallest element
int minIndex = begin; //hint
for(int i = begin; i
if(arr[begin - 1]
minIndex = begin;
} else
minIndex = begin - 1;
}
return minIndex;
}
//Insertion Sort
public void insertionSort() {
for(int i = 0; i
/ote -1 above since were dealing with neighbors (a, a+1)
int current = IntList[i];
//int hole = i;
while( i > 0 && IntList[i - 1] > current ) { //while out of place
//slide data to the left moving the hole left
.
. // more code goes here
.
.
}
}
}
}
SortDriver class:
/** * This class is provided mainly as the driver for you to test your implemented methods * Uncomment and run the corresponding code as you progress. */ public class SortDiver { /*public static void main(String[] args) { MyArrayList array = new MyArrayList(); MyArrayList other = new MyArrayList(); System.out.print("Object instance lists: "); for(int i = 0; i
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started