I have been looking for a while for a way to sort an arraylist without using collections.sort as my own logic is flawed and I have been having a lot of trouble.
I need to sort it in a way that I can use a method I created that basically does what collections.swap does in order to completely sort an arraylist.
Here is my code:
public static void mySort(ArrayList<Double> sort){
int min = 0;
int i;
int j = 0;
for(i = 0; i < sort.size() - 1; i++) {
min = i;
mySwap(sort, j ,min);
for(j = 0; j < sort.size() -1;j++){
if(j < min ){
min = j;
}
}
}
}
public static void mySwap(ArrayList<Double> a, int x, int y){
double temp = a.get(x);
a.set(x,a.get(y));
a.set(y,temp);
}
I have been having a lot of trouble of with this. Sorry if it is a question is that harming the community.
Collections.sortnot good for you?