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
Driving to the city, at one point the vehicle you were in, was moving at 80 mph, how fast is it in km/h?
mars1129 [50]

Answer:

128.74 Km/h

Explanation:

5 0
3 years ago
Read 2 more answers
What is the correct procedure for mounting the m240 on the m122a1 tripod after the pintle is attached to the receiver?
cluponka [151]

Using the front sight adjusting tool, loosen (turn counterclockwise) the adjusting screw on the front sight assembly the desired amount. Then tighten (turn clockwise) the opposite side screw on the left exactly the same number of clicks.

<h3>What is a Machine gun ?</h3>

The term "machine gun" refers to a rifled, autoloading, fully automatic weapon intended for continuous direct fire using rifle rounds. Other automatic weapons, such as automatic rifles, are often intended to fire in brief bursts rather than continuously, and are not regarded as real machine guns because of this.

  • Machine guns and other automatic weapons vary in that they fire rounds continually until the shooter lets off of the trigger after pulling it once. Fully automatic guns are uncommon compared to semi-automatic rifles.

Learn more about Machine gun here:

brainly.com/question/1358898

#SPJ4

8 0
2 years ago
Air is compressed by a 40-kW compressor from P1 to P2. The air temperature is maintained constant at 25°C during this process a
AlexFokin [52]

Answer:

the rate of entropy change of the air is -0.1342 kW/K

the assumptions made in solving this problem

- Air is an ideal gas.

- the process is isothermal ( internally reversible process ). the change in internal energy is 0.

- It is a steady flow process

- Potential and Kinetic energy changes are negligible.

Explanation:

Given the data in the question;

From the first law of thermodynamics;

dQ = dU + dW ------ let this be equation 1

where dQ is the heat transfer, dU is internal energy and dW is the work done.

from the question, the process is isothermal ( internally reversible process )

Thus, the change in internal energy is 0

dU = 0

given that; Air is compressed by a 40-kW compressor from P1 to P2

since it is compressed, dW = -40 kW

we substitute into equation 1

dQ = 0 + ( -40 kW )

dQ = -40 kW

Now, change in entropy of air is;

ΔS_{air = dQ / T

given that T = 25 °C = ( 25 + 273.15 ) K = 298.15 K

so we substitute

ΔS_{air =  -40 kW / 298.15 K

ΔS_{air =  -0.13416 ≈ -0.1342 kW/K

Therefore, the rate of entropy change of the air is -0.1342 kW/K

the assumptions made in solving this problem

- Air is an ideal gas.

- the process is isothermal ( internally reversible process ). the change in internal energy is 0.

- It is a steady flow process

- Potential and Kinetic energy changes are negligible.

7 0
3 years ago
Analyze the following ideal transistor circuit. Can use general rule of thumbs for analyzing transistors b-base, c- collector, a
wlad13 [49]

Answer:

a) Vout= 5V

b) Vout= 5V

c) Vbase= 0.6V

d) Vbase= 0.6V

Explanation:

Consider the circuit shown in attachment

a) When Vin is 0V, the base circuit is not turned, so

Ib=0 and Ic=∞ as transistor is not turned on so

Vout =5V

b) When Vin= 5 V,

Ib= (Vin-Vb)/Rb

Ib=(5-0.6)/1000= 0.0044A

Ic= 0.0044×10=0.044A

Vout= 5- 0.044×1000= not real value

Vout= Vce= 5V

c) voltage drop across Vbase= 0.6V

d) Vbase= 0.6V

In all the above cases, the transistor will not be turned on biasing base voltage and resistor values are very high compared to VCC which is 5V in the given circuit

8 0
3 years ago
Read 2 more answers
What might cause birds in population to immigration To the island
loris [4]

Mass forest destruction

temperatures

7 0
3 years ago
Read 2 more answers
Other questions:
  • 4. The outer end of a control arm is attached to the steering knuckle through a
    5·2 answers
  • Elastic recovery: a. Is the strain that remains in a material when it is deformed plastically, then unloaded. b. Is the strain t
    14·1 answer
  • Atmospheric pressure is measured to be 14.769 psia. a. What would be the equivalent reading of a water barometer (inches of H20)
    11·1 answer
  • Several different loads are going to be used with the voltage divider from Part A. If the load resistances are 300 kΩkΩ , 200 kΩ
    7·1 answer
  • A completely mixed activated-sludge process is being designed for a wastewater flow of 10,000 m3/d (2.64 mgd) using the kinetics
    6·1 answer
  • Can you identify the major theme illustrated by each of the following examples? If necessary, you may review the themes in Chapt
    10·1 answer
  • Product service life is determined by a. estimates b. market forces c. liability d. property tests e. failure analysis f. all of
    12·1 answer
  • Multiple poles at the origin. Sketch the asymptotes of the Bode plot magnitude and phase for each of the listed open-loop transf
    5·1 answer
  • Two technicians are discussing torsion bars. Technician A says that many torsion bars are adjustable to allow for ride height ad
    10·1 answer
  • The variation of the pressure of a fluid with density at constant temperature is known as the _____.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!