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
If you get a flat in the front of your car, your car will:
juin [17]

Answer:

stop and might even crash

Explanation:

6 0
2 years ago
True or False: The differential lock in an AWD-equipped vehicle can be used at any time.
Bingel [31]

the answer would be false

7 0
3 years ago
Read 2 more answers
Select the correct statement(s) regarding IEEE 802.16 WiMAX BWA. a. WiMAX BWA describes both 4G Mobile WiMAX and fixed WiMax b.
Gala2k [10]

Answer:

d. all of the statements are correct.

Explanation:

WiMAX Broadband Wireless Access has the capacity to provide service up to 50 km for fixed stations. It has capacity of up to 15 km for mobile stations. WiMAX BWA describes both of 4G mobile WiMAX and fixed stations WiMAX. OFMD is used to increase spectral efficiency of WiMAX and to improve noise performance.

5 0
3 years ago
A car travells at 67.5 km\h in 120 km.how long will it take to reach the destination
Kruka [31]

mark me the brainiest here

average speed (in km/h) of a car stuck in traffic that drives 12 kilometers in 2 hours.

5 0
3 years ago
What phenomenon allows water to reach the top of a building?
Artemon [7]

Answer:

Option C: water pressure.

Explanation:

Water pressure allows water to reach the top of a building.

6 0
3 years ago
Other questions:
  • Once a design is final engineer needs a plan for product
    14·1 answer
  • In Victorious, when everyone was trapped in the RV, who wasn’t? And what were they doing??
    10·1 answer
  • function summedValue = SummationWithLoop(userNum) % Summation of all values from 1 to userNum summedValue = 0; i = 1; % Write a
    11·1 answer
  • Sketch the velocity profile for laminar and turbulent flow.
    15·1 answer
  • A vernier caliper will measure in what ( URGENT)
    10·1 answer
  • or a metal pipe used to pump tomato paste, the overall heat- transfer coefficient based on internal area is 2 W/(m2 K). The insi
    14·1 answer
  • The chart shows the bids provided by four engineers to test a prototype.
    6·1 answer
  • A low-resistance path in a circuit, commonly called a _____ can cause a circuit breaker to trip
    7·1 answer
  • Technician A says when you push the horn button, electromagnetism moves an iron bar inside the horn, which opens and closes cont
    5·2 answers
  • Identify three questions a patient might ask of the nuclear medicine technologist performing a nuclear medicine exam.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!