1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
iren [92.7K]
3 years ago
11

Your application must generate: - an array of thirteen random integers from 1-99, - then prompt the user to select a sorting opt

ion (Bubble Sort, Insertion Sort, Shell Sort, Merge Sort, or Quick Sort)
Engineering
1 answer:
Fynjy0 [20]3 years ago
5 0

Answer:

The code is given which can be pasted in the Javascript file

Explanation:

The code is given as below

package Sorters;

public class javasort

{

private int[] arr=new int[13];

public void bubbleSort(int[] a){

int c,d,temp;

for (c = 0; c < ( 13 - 1 ); c++) {

for (d = 0; d < 13- c - 1; 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("\n[");

for (int i = 0; i < 13; i++){

  System.out.print(a[i]+" ");

}

System.out.print("]");

}

System.out.println("\nSorted list of numbers");

System.out.print("[");

for (int i = 0; i < 13; i++){

  System.out.print(a[i]+" ");

}

System.out.print("]");

}

public void insertionSort(int[] a){

int temp;

for (int i = 1; i < 13; i++) {

for(int j = i ; j > 0 ; j--){

if(a[j] < a[j-1]){

temp = a[j];

a[j] = a[j-1];

a[j-1] = temp;

}

}

System.out.print("\n[");

for (int c = 0; c < 13; c++){

  System.out.print(a[c]+" ");

}

System.out.print("]");

}

System.out.println("\nSorted list of numbers");

System.out.print("[");

for (int i = 0; i < 13; 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 < a.length; 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("\n[");

for (int c = 0; c < 13; c++){

  System.out.print(a[c]+" ");

}

System.out.print("]");

}

System.out.println("\nSorted list of numbers");

System.out.print("[");

for (int i = 0; i < 13; i++){

  System.out.print(a[i]+" ");

}

System.out.print("]");

}

public void MergeSort(int[] a, int low, int high){

int N = high - low;  

if (N <= 1)

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 < N; k++)

{

if (i == mid)

temp[k] = a[j++];

else if (j == high)

temp[k] = a[i++];

else if (a[j]<a[i])

temp[k] = a[j++];

else

temp[k] = a[i++];

}

for (int k = 0; k < N; k++)

a[low + k] = temp[k];

System.out.print("\n[");

for (int c = 0; c < 13; c++){

  System.out.print(a[c]+" ");

}

System.out.print("]");

printM(a);

}

public void quickSort(int[] a,int low,int high){

  System.out.print("\n[");

  for (int c = 0; c < 13; 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 <= j)

{

while (a[i] < pivot)

i++;

while (a[j] > pivot)

j--;

if (i <= j)

{

/** swap **/

temp = a[i];

a[i] = a[j];

a[j] = temp;

i++;

j--;

}

}

/** recursively sort lower half **/

if (low < j)

quickSort(a, low, j);

/** recursively sort upper half **/

if (i < high)

quickSort(a, i, high);

printM(a);

}

public void printM(int[] a){

arr=a;

}

public void fPrint(){

  System.out.println("\nSorted list:");

  System.out.print("\n[");

  for (int c = 0; c < 13; c++){

      System.out.print(arr[c]+" ");

  }

  System.out.print("]");

}

}

package mani;

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<13;i++){

a[i]=r.nextInt(99)+1;

}

System.out.print("[");

for (int c = 0; c < 13; c++){

  System.out.print(a[c]+" ");

}

System.out.print("]");

javasort j=new javasort();

System.out.println("\nSelect the sorting algo.\n1.bubbleSort\n2.insertionSort\n3.shellSort\n4.MergeSort\n5.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;

}

}

}

You might be interested in
Blank is common during exercise.
dsp73

Answer:

Sweat

Explanation:

As you exercise you respire and warm up due to energy. In turn, two things happen, blood vessels vasodilate (irrelevant to you) and sweat glands sweat more. this sweat then evaporates and cools down the body.

7 0
2 years ago
In low speed subsonic wind tunnels, the value of test section velocity can be controlled by adjusting the pressure difference be
MArishka [77]

Answer:

Hence the given statement is false.

Explanation:

For low-speed subsonic wind tunnels, the air density remains nearly constant decreasing the cross-section area cause the flow to extend velocity, and reduce pressure. Similarly increasing the world cause to decrease and therefore the pressure to extend.

The speed within the test section is decided by the planning of the tunnel.  

Thus by adjusting the pressure difference won't change the worth of test section velocity.

7 0
3 years ago
Where did fossil fuels come from
Levart [38]

Any fuel such as coal, petroleum (crude oil) or natural gas that has developed within the Earth over millions of years from the decayed remains of bacteria, plants or animals

6 0
3 years ago
Read 2 more answers
The cult of personality that surrounded Joseph Stalin in the Soviet Union led soviet citizens to believe that there was undisput
evablogger [386]

Answer:

The cult of personality that surrounded Joseph Stalin in the Soviet Union led soviet citizens to believe that there was undisputed support for Stalin both among the government and the common people. In turn, this fueled self-censorship and made political change harder. This cult of personality was achieved through propaganda and censorship, as the Communist Party had control of all mass media. This desire to make himself a "god-like" figure was also an attempt to increase acceptance of communism among the people and to boost morale.

Explanation:

7 0
3 years ago
Ayuda!<br> es para mañana
ExtremeBDS [4]
No se ve la foto :( puedes a ser la pregunta otra ves?
8 0
3 years ago
Other questions:
  • What is pre-flush and post flush in petroleum engineering?
    14·1 answer
  • Air is heated from 50 F to 200 F in a rigid container with a heat transfer of 500 Btu. Assume that the air behaves as an ideal g
    10·1 answer
  • The displacement of an oscillating mass is 0.004*sin(7t) meters. What is the peak amplitude of its velocity in meters/second?
    10·1 answer
  • A chemistry student accidentally drops a large mercury thermometer and it breaks. The thermometer contained 2 grams of mercury (
    13·1 answer
  • 37. In ______ combination of drugs, the effects of one drug cancel or diminish
    12·1 answer
  • Assume that light of wavelength 6000A is coming from a star. What is the limit of resolution of a telescope whose objective has
    7·1 answer
  • -Why is it said that using faulty PPE could be just as dangerous as using no PPE at all?
    6·2 answers
  • The acrylic plastic rod is 200 mm long and 15 mm in diameter. If an axial load of 300 N is applied to it, determine the change i
    6·1 answer
  • B) Calculate the FS against uplift and calculate effoctive stress at the base level for water
    11·1 answer
  • Can someone help me plz!!! It’s 23 points
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!