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
g Let the charges start infinitely far away and infinitely far apart. They are placed at (6 cm, 0) and (0, 3 cm), respectively,
irina1246 [14]

Answer:

a) V =10¹¹*(1.5q₁ + 3q₂)

b) U = 1.34*10¹¹q₁q₂

Explanation:

Given

x₁ = 6 cm

y₁ = 0 cm

x₂ = 0 cm

y₂ = 3 cm

q₁ = unknown value in Coulomb

q₂ = unknown value in Coulomb

A) V₁ = Kq₁/r₁

where   r₁ = √((6-0)²+(0-0)²)cm = 6 cm = 0.06 m

V₁ = 9*10⁹q₁/(0.06) = 1.5*10¹¹q₁

V₂ = Kq₂/r₂

where   r₂ = √((0-0)²+(3-0)²)cm = 3 cm = 0.03 m

V₂ = 9*10⁹q₂/(0.03) = 3*10¹¹q₂

The electric potential due to the two charges at the origin is

V = ∑Vi = V₁ + V₂ = 1.5*10¹¹q₁ + 3*10¹¹q₂ = 10¹¹*(1.5q₁ + 3q₂)

B) The electric potential energy associated with the system, relative to their infinite initial positions, can be obtained as follows

U = Kq₁q₂/r₁₂

where

r₁₂ = √((0-6)²+(3-0)²)cm = √45 cm = 3√5 cm = (3√5/100) m

then

U = 9*10⁹q₁q₂/(3√5/100)

⇒ U = 1.34*10¹¹q₁q₂

5 0
3 years ago
A gas stream flowing at 1000 cfm with a particulate loading of 400 gr/ft3 discharges from a certain industrial plant through an
Makovka662 [10]

<u>Solution and Explanation:</u>

Volume of gas stream = 1000 cfm (Cubic Feet per Minute)

Particulate loading = 400 gr/ft3 (Grain/cubic feet)

1 gr/ft3 = 0.00220462 lb/ft3

Total weight of particulate matter = 1000 \mathrm{cfm} \times 400 \mathrm{gr} / \mathrm{tt} 3 \times .000142857 \mathrm{lb} / \mathrm{ft} 3 \times 60=3428.568 \mathrm{lb} / \mathrm{hr}

Cyclone is to 80 % efficient

So particulate remaining = 0.20 \times 3428.568 \mathrm{lb} / \mathrm{hr}=685.7136

emissions from this stack be limited to = 10.0 lb/hr

Particles to be remaining after wet scrubber = 10.0 lb/hr

So particles to be removed = 685.7136- 10 = 675.7136

Efficiency = output multiply with 100/input = 98.542 %

4 0
3 years ago
A vehicle is considered to be legally parked if it is parked _____ or more from a pedestrian crosswalk or a marked or unmarked i
Yuki888 [10]

Answer:

A vehicle is considered to be legally parked if it is parked 20 feet (6 m) or more from a pedestrian crosswalk or a marked or unmarked intersection.

Explanation:

Hello!

I obtained the provided data from the New York State Driver's Manual. I wish it was useful to help you.

Success in your homework!

7 0
3 years ago
Define the following terms: data, database, DBMS, database system, database catalog, program-data independence, user view, DBA,
nalin [4]

Answer:

data - Any form of value in a column of a table in a relational database.

DBMS - Short for Database management system, which is a software that can be used to create, manipulate and view databases, e.g. MS SQL Server.

database system - Same as DBMS.

database catalog - Place where the metadata of a Database including its tables, users etc. exists, e.g. date created, size, number of columns etc. Also known as Data Dictionary.

program-data independence - Program-data independence refers to the design of keeping different levels of database (external, logical and physical) separate and loosely coupled from each other, for easier maintenance or modification work.

DBA - Short for Database Administrator, person responsible for maintaining the database. Its main responsibility is to keep the data clean and safe i.e. data doesn't contain wrong or invalid data, and is safe from viruses and is backed up.

end user - Anyone who is not directly interacting with a database, but through some software, like website or mobile application.

persistent object - An object of a class in a program, that interacts with the underlying database and is responsible for manipulating the database, the program is connected to.

transaction-processing system - A transaction process system is part of a software, responsible for making sure critical business transactions, like crediting or debiting money, either goes through cleanly or doesn't at all.

6 0
4 years ago
Meeeeep
lesya [120]

THANKYOUUU :)

THANKYOUUU :)

THANKYOUUU :)

THANKYOUUU :)

THANKYOUUU :)

THANKYOUUU :)

THANKYOUUU :)

THANKYOUUU :)

THANKYOUUU :)

THANKYOUUU :)

THANKYOUUU :)

THANKYOUUU :)

THANKYOUUU :)

THANKYOUUU :)

THANKYOUUU :)

THANKYOUUU :)

THANKYOUUU :)

THANKYOUUU :)

THANKYOUUU :)

THANKYOUUU :)

THANKYOUUU :)

THANKYOUUU :)

THANKYOUUU :)

THANKYOUUU :)

5 0
3 years ago
Read 2 more answers
Other questions:
  • Block A has a weight of 8 lb. and block B has a weight of 6 lb. They rest on a surface for which the coefficient of kinetic fric
    8·1 answer
  • Assume a person is making a 350 mile trip from Amherst to Washington DC has four modes available to them: air; auto; train; ship
    10·1 answer
  • A gas flows through a one-inlet, one-exit control volume operating at steady state. Considering an adiabatic control volume with
    9·1 answer
  • In sleep, what does REM stand for?
    10·1 answer
  • How is air pressure affected by the shape of an aircraft wing
    14·1 answer
  • The efficiency of a steam power plant can beincreased by bleeding off some of the steam thatwould normally enter the turbine and
    15·1 answer
  • A machine raises 20kg of water through a height of 50m in 10secs. What is the power of the machine.​
    5·1 answer
  • How to plot 0.45 gradation chart for sieve analysis ?
    12·1 answer
  • 3. If nothing can ever be at absolute zero, why does the concept exist?
    8·1 answer
  • The controller determines if a(n) _________ exists by calculating the difference between the SP and the PV.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!