再会!该程序应该对文件中的前 n 个单词进行排序。请帮我在调用方法mergeSort_srt时传递参数。当我运行它时,控制台说
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method mergeSort_srt(int[], int, int) in the type SortingAnalysis is not applicable for the arguments (String[], int, int)
我是 Java 语言编程的新手,我很困惑。请帮我。尽管我想自己找到错误,但我做不到,因为我对这些东西知之甚少,我需要真人的帮助,而不仅仅是在线阅读教程。非常感谢!
import java.io.*;
import java.util.*;
public class SortingAnalysis {
public static void mergeSort_srt(int array[],int lo, int n){
int low = lo;
int high = n;
if (low >= high) {
return;
}
int middle = (low + high) / 2;
mergeSort_srt(array, low, middle);
mergeSort_srt(array, middle + 1, high);
int end_low = middle;
int start_high = middle + 1;
while ((lo <= end_low) && (start_high <= high)) {
if (array[low] < array[start_high]) {
low++;
} else {
int Temp = array[start_high];
for (int k = start_high- 1; k >= low; k--) {
array[k+1] = array[k];
}
array[low] = Temp;
low++;
end_low++;
start_high++;
}
}
}
public static void main(String[] args) {
final int NO_OF_WORDS = 10000;
try {
Scanner file = new Scanner(new File(args[0]));
String[] words = new String[NO_OF_WORDS];
int i = 0;
while(file.hasNext() && i < NO_OF_WORDS) {
words[i] = file.next();
i++;
}
long start = System.currentTimeMillis();
mergeSort_srt(words, 0, words.length-1);
long end = System.currentTimeMillis();
System.out.println("Sorted Words: ");
for(int j = 0; j < words.length; j++) {
System.out.println(words[j]);
}
System.out.print("Running time: " + (end - start) + "ms");
}
catch(SecurityException securityException) {
System.err.println("You do not have proper privilege to access the files.");
System.exit(1);
}
catch(FileNotFoundException fileNotFoundException) {
System.err.println("Error accessing file");
System.exit(1);
}
}
}