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
Harlin is designing a new car engine that does not create pollution. Which technological design factor is probably the most
kari74 [83]

Answer: environmental impact

Explanation:

From the question, we are informed that Harlin is designing a new car engine that does not create pollution.

The technological design factor which is probably the most important for the design is the impact on the environment.

Pollution has a negative effect on the environment a d doing this shows that emphasis is placed on how the environmental issue of pollution can be tackled.

8 0
3 years ago
An array of electronic chips is mounted within a sealedrectangular enclosure, and colling is implemented by attaching analuminum
Licemer1 [7]

Answer:

Base temperature is 46.23 °C

Explanation:

I've attached explanations

6 0
3 years ago
Match each context to the type of the law that is most suitable for it.
Bas_tet [7]

Answer:

sorry i dont understand the answer

Explanation:

but i think its a xd jk psml lol

5 0
3 years ago
What is the next measurement after 2' -6" on the architect's scale?
Diano4ka-milaya [45]

Answer: I am not for sure

Explanation:

6 0
3 years ago
3.94 x 105) + (2.04 x 105)
Flura [38]
627.9 is the answer
6 0
3 years ago
Other questions:
  • A spherical, stainless steel (k 16 W m1 K-1) tank has a wall thickness of 0.2 cm and an inside diameter of 10 cm. The inside sur
    12·1 answer
  • One cylinder in the diesel engine of a truck has an initial volume of 650 cm3 . Air is admitted to the cylinder at 35 ∘C and a p
    7·1 answer
  • Automotive service P2 Wastewater Management and Handling Spins
    9·1 answer
  • While having a discussion, Technician A says that you should never install undersized tires on a vehicle. The vehicle will be lo
    11·1 answer
  • The rate at which velocity changes is called?
    5·2 answers
  • One kilogram of air, initially at 5 bar, 350 K, and 3 kg of carbon dioxide (CO2), initially at 2 bar, 450 K, are confined to opp
    14·1 answer
  • In sleep, what does REM stand for?
    10·1 answer
  • Which of the following is part of the highway
    11·2 answers
  • Based on your reading of the following, how does a triple save a fire department in time?
    5·1 answer
  • The size of an engine is called the engine
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!