美好的一天!这个程序应该排序文件中的前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)
我是新来编程expecially在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);
}
}
}
哎呀,我很抱歉,我只是从另一个窗口复制粘贴错误。感谢您的认可!但那真的是mergeSort_srt。我真正的问题是参数的传递。 – 2012-07-08 13:13:55
@FirstLady,我根据您的更改更新了我的答案。 – 2012-07-08 13:21:14