Question
Convert this Java program to MIPS assembly language EXACTLY HOW IT IS. I will give good feedback and a rating if you can tackle this
Convert this Java program to MIPS assembly language EXACTLY HOW IT IS. I will give good feedback and a rating if you can tackle this and it works. NOTE: make it an array of size 10 not 50000.
package homework6;
import java.util.Scanner;
import java.util.Arrays;
import java.util.Random;
public class SortingArrays {
static int arraySize = 50000;
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int[] sortedArray = new int[arraySize];
int[] reverseArray = new int[arraySize];
int[] twentyArray = new int[arraySize];
int[] eightyArray = new int[arraySize];
Random generator = new Random();
for(int i = 0; i < twentyArray.length; i++) {
twentyArray[i] = generator.nextInt();
}
Arrays.sort(twentyArray,0,arraySize / 5);
for(int i = 0; i < eightyArray.length; i++) {
eightyArray[i] = generator.nextInt();
}
Arrays.sort(eightyArray,0,arraySize * 4 / 5);
for(int i = 0; i < sortedArray.length; i++) {
sortedArray[i] = i + 1;
}
for(int i = reverseArray.length - 1; i >= 0 ; i--) {
reverseArray[i] = i;
}
insertionSort(sortedArray);
insertionSort(reverseArray);
insertionSort(twentyArray);
insertionSort(eightyArray);
selectionSort(sortedArray);
selectionSort(reverseArray);
selectionSort(twentyArray);
selectionSort(eightyArray);
quickSort(sortedArray);
quickSort(reverseArray);
quickSort(twentyArray);
quickSort(eightyArray);
}
// insertion sort
public static void insertionSort (int[] a) {
int comparisons = 0;
int swaps = 0;
double totalTime = 0.0;
for(int i = 1; i < a.length; i++) {
int temp = a[i];
int j;
for(j = i - 1; j >= 0 && temp < a[j]; j-- ) {
a[j + 1] = a[j];
a[j + 1] = temp;
}
}
}
// selection sort
public static void selectionSort(int[] arr) {
for(int i = 0; i < arr.length - 1; i++) {
int index = i;
for(int j = i + 1; j < arr.length; j++) {
if(arr[j] < arr[index])
index = j;
int smallerNumber = arr[index];
arr[index] = arr[i];
arr[i] = smallerNumber;
}
}
}
// quick sort
public static void quickSort(int[] qarr) {
int low = 0;
int high = qarr.length - 1;
int pivot = qarr[high];
int i = (low-1); // index of smaller element
for (int j=low; j
{
// If current element is smaller than or
// equal to pivot
if (qarr[j] <= pivot)
{
i++;
// swap arr[i] and arr[j]
int temp = qarr[i];
qarr[i] = qarr[j];
qarr[j] = temp;
}
}
// swap arr[i+1] and arr[high] (or pivot)
int temp = qarr[i+1];
qarr[i+1] = qarr[high];
qarr[high] = temp;
}
// merge sort
// Merges two subarrays of arr[].
// First subarray is arr[l..m]
// Second subarray is arr[m+1..r]
// MERGE SORT
public static Stats mergeSort(int[] array) {
Stats stats = new Stats();
long startTime = System.nanoTime();
setUpMerge(array, 0, array.length - 1);
stats.incMillis(System.nanoTime() - startTime);
return stats;
}
/**
* This method is called recursively to divide the array
* into each of the groups to be sorted.
*/
private static void setUpMerge(int[] array, int lower, int higher) {
if (lower < higher) {
int middle = lower + (higher - lower) / 2;
setUpMerge(array, lower, middle);
setUpMerge(array, middle + 1, higher);
//System.out.println(lower + " " + middle + " " + higher);
doTheMerge(array, lower, middle, higher);
}
}
/**
* This method merges the elements in two subgroups
* (start, middle) and (middle + 1, higher) in ascending order
*/
private static void doTheMerge(int[] array, int lower, int middle, int higher) {
int[] tempArray = new int[array.length];
for (int i = lower; i <= higher ; i++) tempArray[i] = array[i];
int i = lower;
int j = middle + 1;
int k = lower;
while (i <= middle && j <= higher) {
if (tempArray[i] < tempArray[j])
array[k] = tempArray[i++];
else array[k] = tempArray[j++];
k++;
//System.out.println(Arrays.toString(array));
}
while (i <= middle) array[k++] = tempArray[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