【发布时间】:2014-01-07 17:34:12
【问题描述】:
我正在尝试使用 冒泡排序 对数组进行排序,但它不起作用。它说'必需:变量,找到:值'
Array.java:143:错误:意外类型
temp.get(d) = temp.get(d+1);
^
必填:变量
找到:值
Array.java:144:错误:意外类型
temp.get(d+1) = 交换;
^
必需:变量
找到:值
所以给出了Main,我需要做的就是编写这个冒泡排序函数
这是我写的
public static void bubbleSort(Array<Integer> lista){
boolean swapped;
Array<Integer> temp;
int n;
n= temp.size;
int swap;
for (int c = 0; c < ( n - 1 ); c++) {
for (int d = 0; d < n - c - 1; d++) {
if (temp.get(d) > temp.get(d+1))
{
swap = temp.get(d);
temp.get(d) = temp.get(d+1);
temp.get(d+1) = swap;
}
}
}
}
这是给出的主要内容
public static void main(String[] args) throws IOException{
BufferedReader stdin = new BufferedReader( new InputStreamReader(System.in));
String s = stdin.readLine();
int N = Integer.parseInt(s);
Array<Integer> niza =new Array<Integer>(N);
bubbleSort(niza);
for(int i=0;i<N;i++){
s = stdin.readLine();
niza.set(i, Integer.parseInt(s));
}
System.out.println(brojDoProsek(niza));
}
如何解决此错误?
【问题讨论】:
-
您不能分配给函数。你正在寻找
set()。
标签: java arrays sorting bubble-sort