Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help!!! Need pseudo code or flowchart for the following program. Due soon!! Code works fine, no help with it. *Attached is a description of the

Help!!! Need pseudo code or flowchart for the following program. Due soon!! Code works fine, no help with it. *Attached is a description of the problem*
public class JavaSort {
private int[] arr=new int[13];
public void BubbleSort(int[] a){
int c,d,temp;
for (c = 0; c
for (d = 0; d
if (a[d] > a[d+1]) /* For descending order use
{
temp = a[d];
a[d] = a[d+1];
a[d+1] = temp;
}
}
System.out.print(" [");
for (int i = 0; i
System.out.print(a[i]+" ");
}
System.out.print("]");
}
System.out.println(" Sorted list of numbers:");
System.out.print("[");
for (int i = 0; i
System.out.print(a[i]+" ");
}
System.out.print("]");
}
public void InsertionSort(int[] a){
int temp;
for (int i = 1; i
for(int j = i ; j > 0 ; j--){
if(a[j]
temp = a[j];
a[j] = a[j-1];
a[j-1] = temp;
}
}
System.out.print(" [");
for (int c = 0; c
System.out.print(a[c]+" ");
}
System.out.print("]");
}
System.out.println(" Sorted list of numbers:");
System.out.print("[");
for (int i = 0; i
System.out.print(a[i]+" ");
}
System.out.print("]");
}
public void ShellSort(int[] a){
int increment = a.length / 2;
while (increment > 0)
{
for (int i = increment; i
{
int j = i;
int temp = a[i];
while (j >= increment && a[j - increment] > temp)
{
a[j] = a[j - increment];
j = j - increment;
}
a[j] = temp;
}
if (increment == 2)
increment = 1;
else
increment *= (5.0 / 11);
System.out.print(" [");
for (int c = 0; c
System.out.print(a[c]+" ");
}
System.out.print("]");
}
System.out.println(" Sorted list of numbers:");
System.out.print("[");
for (int i = 0; i
System.out.print(a[i]+" ");
}
System.out.print("]");
}
public void MergeSort(int[] a, int low, int high){
int N = high - low;
if (N
return;
int mid = low + N/2;
// recursively sort
MergeSort(a, low, mid);
MergeSort(a, mid, high);
// merge two sorted subarrays
int[] temp = new int[N];
int i = low, j = mid;
for (int k = 0; k
{
if (i == mid)
temp[k] = a[j++];
else if (j == high)
temp[k] = a[i++];
else if (a[j]
temp[k] = a[j++];
else
temp[k] = a[i++];
}
for (int k = 0; k
a[low + k] = temp[k];
System.out.print(" [");
for (int c = 0; c
System.out.print(a[c]+" ");
}
System.out.print("]");
printM(a);
}
public void QuickSort(int[] a,int low,int high){
System.out.print(" [");
for (int c = 0; c
System.out.print(a[c]+" ");
}
System.out.print("]");
int i =low, j = high;
int temp;
int pivot = a[(low + high) / 2];
/** partition **/
while (i
{
while (a[i]
i++;
while (a[j] > pivot)
j--;
if (i
{
/** swap **/
temp = a[i];
a[i] = a[j];
a[j] = temp;
i++;
j--;
}
}
/** recursively sort lower half **/
if (low
QuickSort(a, low, j);
/** recursively sort upper half **/
if (i
QuickSort(a, i, high);
printM(a);
}
public void printM(int[] a){
arr=a;
}
public void fPrint(){
System.out.println(" Sorted list of numbers:");
System.out.print("[");
for (int c = 0; c
System.out.print(arr[c]+" ");
}
System.out.print("]");
}
}
import java.util.Random;
import java.util.Scanner;
public class JavaSortTest {
public static void main(String[] args){
int[] a=new int[13];
Random r=new Random();
for(int i=0;i
a[i]=r.nextInt(99)+1;
}
System.out.print("[");
for (int c = 0; c
System.out.print(a[c]+" ");
}
System.out.print("]");
JavaSort j=new JavaSort();
System.out.println(" Select the sorting algorithm: 1. BubbleSort 2. InsertionSort 3. ShellSort 4. MergeSort 5. QuickSort ");
Scanner s=new Scanner(System.in);
int opt=s.nextInt();
switch(opt){
case 1:
j.BubbleSort(a);
break;
case 2:
j.InsertionSort(a);
break;
case 3:
j.ShellSort(a);
break;
case 4:
j.MergeSort(a, 0, 13);
j.fPrint();
break;
case 5:
j.QuickSort(a ,0, 12);
j.fPrint();
break;
}
}
}
image text in transcribed
L (5%) Understand the Problem, (10%)Design, Submission will include a written description for each sorting algorithm. Students must display an understand of these algorithms. (7596) Implementation (Code). (10%) Test Plan. Please see examples provided on Blackboard. Don't forget the screen capture/s. Ill. Problem. Write a Java Sorting Application with two classes, JavaSort and JavaSortTest. Your JavaSort Class, as a minimum must contain sorting methods for BubbleSort, InsertionSort, ShellSort, MergeSort, and QuickSort. Your application must generate: an array of thirteen random integers from 1-99, then prompt the user to select a sorting option (Bubble Sort, Insertion Sort, Shell Sort, Merge Sort, or Quick Sort) Your application must: Account for duplications Show each completed pass of the sort on a new line with arrays surrounded by square brackets until sorted similar to the examples completed in class as part of the In-Class Exercise

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Students also viewed these Databases questions

Question

0; int sum for (int x=15; x

Answered: 1 week ago