I'm try to check if the passed array is sorted or not:
public static boolean isSorted(int[] list){
boolean isSorted = true;
int[] arr = list;
selectionSort(arr);
for (int i = 0; i < list.length; i++) {
if (arr[i] != list[i]){
isSorted = false;
break;
}
}
return isSorted;
}
I passed the array list
and make array arr
equal to list, what happened is the array list
became equal to array arr
after sorting.
What is java rules for that? and what should i do to separate arr
from list
?