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
Discuss four (4) advantages of direct and indirect water supply system.
Reil [10]

Answer and Explanation:

Some of the advantages of direct water supply system are:

  • Smaller size of the cistern
  • No risk of polluted water
  • Ease of installation
  • Lower pipe work

Some of the advantages of indirect water supply system are:

  • It can be pumped completely
  • Lower demand on the main source
  • Minimization of wear and tear on taps
  • Larger size of the cistern.
7 0
3 years ago
Read 2 more answers
Please help me with this question​
kap26 [50]

Answer:

The current through each lamp is 0.273 Amperes

Power dissipated in each lamp is 0.082W

Explanation:

Battery v = 1.5 V

Each lamp has resistance, r = 1.1 Ohms

The 5 lamps in series will therefore have total resistance, R = 5 * 1.1 = 5.5 Ohms

The current through each lamp, I = v/R = 1.5 / 5.5 = 0.273 Amperes

Power dissipated in each lamp = I² * r = 0.273² * 1.1 = 0.082W

3 0
3 years ago
Write a function "funthree" that will print a box of characters. The function will always receive as the first input argument th
stiv31 [10]

Answer: i8g7ieusgr7eytuu7esieso87 sugr7pi8y8hiuh9yehroe998 rydyh9 t9ry9 7 fdgerje 78re87es 7yehr87ehtu9hu7b puuhihugogi;ghi uhugyug fhglhfu fufbiup hughghuihu fhuihihiuhg uhfuhuig8fguh hguihfhjliigihfuhf;gjihgh hfuyt8uyiiohiodohi

Explanation: so first you are going to hyigfgegidii9thdf5dh8yy7 gdiuigp 87hgiuf 8yhijh gihoighhgd

4 0
4 years ago
How many gallons of water is needed to fill a pool.
zalisa [80]

Answer:

depends on the size

Explanation:

Length x width x depth x 7.5 = volume (in gallons)

Length times width gives the surface area of the pool. Multiplying that by the depth gives the volume in cubic feet. Since there are 7.5 gallons in each cubic foot, multiply the cubic feet of the pool by 7.5 to arrive at the volume of the pool, expressed in gallons.

6 0
3 years ago
Read 2 more answers
A 0.3 m3 rigid tank initially contains refrigerant-134a at 14°C. At this state, 55% of the mass is in the vapor phase, and the r
Oksanka [162]

Answer:

I am a girl want private photos

Explanation:

8 0
3 years ago
Other questions:
  • An adiabatic turbine is operating with an ideal gas working fluid of fixed inlet temperature and pressure (T1, P1) and a fixed e
    6·1 answer
  • Which of these is least likely a step in replacing a failed compressor?
    12·2 answers
  • After the 2015 AFC Championship football game between the New England Patriots and the Indianapolis Colts, it was alleged that t
    10·1 answer
  • Explain the process of predicting equipment failure?
    12·1 answer
  • 9. A vehicle is having routine maintenance performed.
    7·1 answer
  • Is (3x+1)(4x-5) the factor form of 12x^2-11x-5?
    12·2 answers
  • Select the correct text in the passage.
    6·2 answers
  • What is the correct order of the different environments from coldest to hottest?
    12·2 answers
  • A person’s ability to use understand and relate to technology is known as :
    10·1 answer
  • Consider an infinite lattice with coordination number z in which every site is occupied by a molecule. (As a reminder, the coord
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!