What I am having trouble with is understanding how the list of integers will be sorted into an array after they are read. How would I call the sorting method to sort these files and then put them into an array?
Here is my code thus far for reading the file:
public void sortFile ( String fileName ) throws IOException {
File file1 = new File("F1.txt");
Scanner inputFile1 = new Scanner(file1);
while ( inputFile1.hasNext()) {
int numbers1 = inputFile1.nextInt();
}
inputFile1.close();
File file2 = new File("F2.txt");
Scanner inputFile2 = new Scanner(file2);
while ( inputFile2.hasNext()) {
int numbers2 = inputFile2.nextInt();
}
inputFile2.close();
}
This is my selection sort method that I'm going to use to sort the files.
public int selectionSort ( ) {
int startScan, i, minIndex, minValue, counter = 0;
for ( startScan = 0; startScan < (numbers.length - 1); startScan++) {
minIndex = startScan;
minValue = numbers[startScan];
counter++;
for ( i = startScan + 1; i < numbers.length; i++ ) {
if ( numbers[i] < minValue ) {
minValue = numbers[i];
minIndex = i;
}
}
numbers[minIndex] = numbers[startScan];
numbers[startScan] = minValue;
}
return counter;
}

New Topic/Question
Reply




MultiQuote




|