我正在寫一個選擇排序程序,它仍然是未完成的,所以有很多錯誤,但我'我想找首先要解決的是,日食錯誤不斷給我:arraylist給「不能解決」和「不能解決一個類型」的錯誤(日食)
thelist cannot be resolved to a type
,並再次,在程序的其餘部分:
thelist cannot be resolved
我的程序是這樣的:
import java.util.ArrayList;
public class SelectionSort {
public static void main(String[] args) {
final int N = Integer.parseInt(args[0]);
//populate list with number from 1 to N
// Create an ArrayList containing Integer type elements
ArrayList<Integer> thelist = new ArrayList();
//while loop to accept a new value from random generator
//call sort method
}
public static void sort(final thelist<Integer> list) {
// declare an int variable to hold value of index at which the element
// has the smallest value
int smaller = 0;
int b=0;
// declare an int variable to hold the smallest value for each iteration
// of the outer loop
int smallerindex = 0;
for(int a=1;a<thelist.size();a++){
/* find the index at which the element has smallest value */
// initialize variables
smaller = thelist.get(a-1);
smallerindex = a-1;
for(b=a;b<thelist.size();b++){
if(thelist.get(b)<smaller){
// update smallest
smaller = thelist.get(b);
smallerindex = b;
}
}
// do nothing if the curIndex has the smallest value
//Swap the smallest element with the first element of unsorted subarray
int temp = thelist.get(destIndex);
thelist.set(destIndex, thelist.get(sourceIndex));
thelist.set(sourceIndex, temp);
}
}
}
'thelist'不是一個有效的類型。排序方法的簽名應該是'sort(ArrayList list)'。 –
2015-03-24 22:58:39
謝謝你,工作! – 2015-03-24 22:59:50