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
mixas84 [53]
3 years ago
10

[10] Create a program called SelectionSort.java that implements the Selection Sort algorithm (The Art of Computer Programming -

Donald Knuth). The algorithm is as follows: The program should be able to do the following: accepts one command line parameter. The parameter specifies the path to a text file containing the integers to be sorted. The structure of the file is as follows: There will be multiple lines in the file (number of lines unknown). Each line will contain multiple integers, separated by a single whitespace. reads the integers from the text file in part a into an array of integers. sort the integers in ascending order, and then prints out a sorted version of these integers, one per line. The implementation should follow the given the pseudo code/algorithm description.
Engineering
1 answer:
Alex787 [66]3 years ago
8 0

Answer:

import java.io.File;

import java.io.FileNotFoundException;

import java.util.ArrayList;

import java.util.Scanner;

public class SelectionSort {

  public static void main(String[] args) throws FileNotFoundException {

      //For array

      ArrayList<Integer>array=new ArrayList<Integer>();

      //If argument found

      if(args.length>=1) {

          //File path

          Scanner sc=new Scanner(new File(args[0]));

          //Loop until end

          while(sc.hasNextLine()) {

              //Read each line and add into array

              String[] temp=sc.nextLine().split(" ");

              for(int i=0;i<temp.length;i++) {

                  array.add(Integer.parseInt(temp[i]));

              }

          }

          //Display array

          System.out.println("Display array: ");

          printArray(array);

          System.out.println("\nDisplay array after sort: ");

          sortArray(array);

          printArray(array);

      }

      //If argument not found

      else {

          System.out.println("Argument not found!!!");

      }

  }

  //Method to print array

  public static void printArray(ArrayList<Integer>array) {

      for(int i=0;i<array.size();i++) {

          System.out.println(array.get(i));

      }

  }

  //Method to sort array using straight selection sort

  public static void sortArray(ArrayList<Integer>array) {

      //Step1

      for(int j=array.size()-1;j>=1;j--) {

          int max=array.get(j);

          int index=j;

          //Step2

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

              if(max<array.get(k)) {

                  max=array.get(k);

                  index=k;

              }

          }

          //Step3

          array.set(index,array.get(j));

          array.set(j,max);

      }

  }

}

Explanation:

You might be interested in
ANSWER QUICK<br>Why did Winston Churchill take over for Neville Chamberlain shortly after ww2? ​
kenny6666 [7]

Answer:neville chamberlain died

Explanation:

4 0
4 years ago
Define an ADT for a two-dimensional array of integers. Specify precisely the basic operations that can be performed on such arra
VashaNatasha [74]

Answer:

Explanation:

ADT for an 2-D array:

struct array{

int arr[10];

}arrmain[10];

An application that stores an array with 1000 rows and 1000 columns, where less than 10,000 of the array values are non-zero. The two different implementations for such arrays that would be more space efficient than a standard two-dimensional array implementation requiring one million positions are :

1) struct array{

int *p;

}arr[1000];

2) struct array{

int *p;

}arr[1000];

6 0
3 years ago
How are the accelerator and brake pedal positioned in relation to each other? A. The brake pedal is to the right of the accelera
Lunna [17]

Answer:B

Explanation:

7 0
4 years ago
A water pump delivers 3 hp of shaft power when operating. If the pressure differential between the outlet and the inlet of the p
Natali [406]

Answer:

Mechanical Efficiency =  83.51%

Explanation:

Given Data:

Pressure difference = ΔP=1.2 Psi

Flow rate = V=8ft^3/s\\

Power of Pump = 3 hp

Required:

Mechanical Efficiency

Solution:

We will first bring the change the units of given data into SI units.

P=1.2*6.895 = 8.274KPa\\V=8*0.00283=0.226 m^3/s\\P=3*0.746=2.238KW

Now we will find the change in energy.

Since it is mentioned in the statement that change in elevation (potential energy) and change in velocity (Kinetic Energy) are negligible.

Thus change in energy is

=(Mass * change in P)/density\\= \frac{M*P}{p}\\\\

As we know that Mass = Volume x density

substituting the value

Energy = Volume * density x ΔP / density

Change in energy = Volumetric flow x ΔP

Change in energy = 0.226 x 8.274 = 1.869 KW

Now mechanical efficiency = change in energy / work done by shaft

Efficiency = 1.869 / 2.238

Efficiency = 0.8351 = 83.51%

5 0
3 years ago
Question in image. Question from OSHA.
Maru [420]

Answer:

welding screens

Explanation:

4 0
3 years ago
Read 2 more answers
Other questions:
  • Water at 20 °C is flowing with velocity of 0.5 m/s between two parallel flat plates placed 1 cm apart. Determine the distances f
    5·1 answer
  • The fouling on the heat exchanger surfaces causes additional thermal resistance, thus decreases the heat transfer rate. a)- True
    11·1 answer
  • 1. How does manufacturing help strengthen<br> the economy?
    15·1 answer
  • Complete the following sentence.
    10·1 answer
  • Side milling cutter is an example of ______ milling cutter.
    6·1 answer
  • The diameter of a cylindrical water tank is Do and its height is H. The tank is filled with water, which is open to the atmosphe
    11·1 answer
  • New ventures that are based on strategic value, such as valuable technology, are attractive while those with low or no strategic
    12·2 answers
  • Construction lines are thick lines true false
    11·2 answers
  • 40 POINTS IF ANSERED WITHIN 10 MINS
    13·2 answers
  • ​please how to drawing mechanical drawing after connecting the all parts thanks
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!