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
A rectangular region ABCD is to be built inside a semicircle of radius 10 m with points A and B on the line for the diameter and
Talja [164]

Answer:A rectangular region ABCD is to be built inside a semicircle of radius 10 m with points A and B on the line for the diameter and points C and D on the semicircle with CD parallel to AB. The objective is to find the height h * that maximizes the area of ABCD.

Formulate the optimization problem.

Explanation:A rectangular region ABCD is to be built inside a semicircle of radius 10 m with points A and B on the line for the diameter and points C and D on the semicircle with CD parallel to AB. The objective is to find the height h * that maximizes the area of ABCD.

Formulate the optimization problem.

7 0
3 years ago
A rigid insulated tank is divided into 2 equal compartments by a thin rigid partition. One of the compartments contains air, ass
Illusion [34]
Https://www.slader.com/discussion/question/an-insulated-rigid-tank-is-divided-into-two-equal-parts-by-a-partition-initially-one-part-contains-4/



there will be the answer

6 0
2 years ago
A growing trend in urban design is the concept of a rooftop garden. If every building in a city were to install a rooftop garden
vlabodo [156]

Answer:The Urban heat island temperature will be REDUCED.

Two Impacts of Rooftop gardens

1) provision of shade against Sunlight.

2) It helps to purify the air around the building.

Explanation: Rooftop gardens are gardens made on top of the roofs of buildings, it is a Green initiative aimed at helping to improve the overall Environment.

Rooftop gardens have several significant benefits which includes

Reduction of the surrounding temperatures and the Urban heat Island temperatures.

Rooftop gardens helps to shade the roof from the direct impacts of harsh weather conditions.

Generally, plants are known as air purifiers as they remove the excess Carbondioxide around the environment through photosynthesis, and they also help to release water vapor which will help to improve the humidity of the environment.

5 0
3 years ago
The domain of discourse is the members of a chess club. The predicate B(x, y) means that person x has beaten person y at some po
satela [25.4K]

Answer:A. No one has ever beat Nancy.

Explanation:

The dormain of discourse in a simple language is the set of entities upon which our discussions are based when discussing about something.

The dormain of discourse is also known simply as universe, can also be said to be a set of entities o

upon which certain variables of interest in some formal treatment may range.

The dormain of discourse is generally attributed to Augustus De Morgan, it was also extensively used by George Boole in his Laws of Thought.

THE LOGICAL UNDERSTANDING OF THE THE QUESTION IS THAT NO ONE HAS EVER BEAT NANCY.

8 0
3 years ago
N DevOps, high levels of automation are expected, which increases productivity. Which fact illustrates this productivity increas
Bess [88]

Answer:

Less intervention of humans.

Explanation:

This fact illustrate that less intervention of human in the production is the main cause for increase in productivity because use of machinery completed the work in less time as compared to the use of human labour. In many industries, machines takes the place of humans which increases the production of products but at the same time, increase the unemployment rate in the society. Making the whole industry on automation can increase the productivity of products in less time.

3 0
3 years ago
Other questions:
  • If there are 16 signal combinations (states) and a baud rate (number of signals/second) of 8000/second, how many bps could I sen
    7·1 answer
  • The ratio of the weight of a substance to the weight of equal volume of water is known as a) Density b) specific gravity c) spec
    8·1 answer
  • Policy makers in the U.S. government have long tried to write laws that encourage growth in per capita real GDP. These laws typi
    6·1 answer
  • Bridge A is the longest suspension bridge in a Country. Bridge B is 5555 feet shortershorter than Bridge A. If the length of Bri
    9·1 answer
  • Tanya Pierce, President and owner of Florida Now Real Estate is seeking your assistance in designing a database for her business
    9·1 answer
  • Which element of Miranda's character is best illustrated by this excerpt?
    15·1 answer
  • The current through a 10-mH inductor is 10e−t∕2 A. Find the voltage and the power at t = 8 s.
    15·2 answers
  • Thoughts about drinking and driving
    12·2 answers
  • A compressor receives air at 290 K, 95 kPa and shaft work of 5.5 kW from a gasoline engine. It should deliver a mass flow rate o
    7·1 answer
  • The thrust angle is checked by referencing
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!