I got an ArrayList which contains next data : coordX
(int) , coordY
(int) , length
(int), position
(String).I sort this array by the length
field. How can I give priority if the lengths are equal by the position
filed (priority will have that length that has horizontal position). For example, given the input:
coordX = 1 , coordY = 0 , length = 2 , position - vertical
coordX = 5 , coordY = 3 , length = 2 , position - horizontal
coordX = 1 , coordY = 6 , length = 4 , position - horizontal
coordX = 3 , coordY = 6 , length = 1 , position - "1x1"
Output should be :
coordX = 1 , coordY = 6 , length = 4 , position - horizontal
coordX = 5 , coordY = 3 , length = 2 , position - horizontal
coordX = 1 , coordY = 0 , length = 2 , position - vertical
coordX = 3 , coordY = 6 , length = 1 , position - "1x1"
Here is what I have :
public static void insertionSort(ArrayList<sort> srt) {
int i,j;
for (i = 1; i < srt.size(); i++) {
sort tmp = srt.get(i);
j = i;
while ((j > 0) && (srt.get(j - 1).length > tmp.length)) {
srt.set(j, srt.get(j - 1));
j--;
}
srt.set(j, tmp);
}
}