I'm trying to sort an array using Bubble sort, but it won't work. It says 'required: variable, found: value'
Array.java:143: error: unexpected type
temp.get(d) = temp.get(d+1);
^
required: variable
found: value
Array.java:144: error: unexpected type
temp.get(d+1) = swap;
^
required: variable
found: value
So the Main is given, and all I need to do is write this Bubble sort function
This is what I wrote
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;
}
}
}
}
And here's the Main that was given
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));
}
How do I fix this error?
set().