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
In your Reader/Writer Notebook, write a short first-person narrative from the perspective of the bank clerk, describing her phys
guajiro [1.7K]
BAHHHHAHHH HOFHOFYOCIGC
5 0
3 years ago
To prevent drainage of the transmission fluid from the converter when the
-BARSIC- [3]
Answer
D I think
Explanation
4 0
2 years ago
Rubber bushings are used on suspensions to
Harlamova29_29 [7]
D. All of the above
4 0
3 years ago
The __________________ refers to the main screen of the computer.
Sedbober [7]

Answer:

<em>D</em><em>e</em><em>s</em><em>k</em><em>t</em><em>o</em><em>p</em>

Explain:

<em>Desktop refers to the main screen of the computer. It is the first screen you see after logging in. The desktop’s appearance can vary widely because it is highly customizable, but generally desktops will feature a large image, icons, and a taskbar(covered later on this page).</em>

4 0
2 years ago
I want a problems and there solutions of The inception of cavitation?​
Ugo [173]

Answer:

The overview of the given scenario is explained in explanation segment below.

Explanation:

  • The inception of cavitation, that further sets the restriction for high-pressure and high-free operation, has always been the matter of substantial experimental study over the last few generations.
  • Cavitation inception would be expected to vary on the segment where the local "PL" pressure mostly on segment keeps falling to that are below the "Pv" vapor pressure of the fluid and therefore could be anticipated from either the apportionment of the pressure.

    ⇒  A cavitation number is denoted by "σ" .

4 0
3 years ago
Other questions:
  • Steam flows at steady state through a converging, insulated nozzle, 25 cm long and with an inlet diameter of 5 cm. At the nozzle
    11·1 answer
  • The dry unit weight of a soil sample is 14.8 kN/m3.
    12·1 answer
  • Steel riverts in aluminium drain gutters leak after two years. is it galvanic corrosion? ​
    5·1 answer
  • What should you consider when choosing the type of hearing protection you use?
    15·1 answer
  • How many steps are there in the problem-solving process?
    9·2 answers
  • Estimate the luminosity of a 3 -solar-mass main-sequence star; of a 9 -solar-mass main-sequence star. Can you easily estimate th
    5·1 answer
  • TWO SENTENCES!!! What is something that you have used today that was designed by an engineer? What parts were designed by an eng
    11·2 answers
  • Three 1.83 in. diameter bolts are used to connect the axial member to the support in a double shear connection. The ultimate she
    8·1 answer
  • On calculating which of the following quantities , does the body have an effect in simple projectile motion?​
    10·1 answer
  • 3. Which instrument measures the height above the ground?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!