The array I have before and how we want it after the sorting:
Before:
Box Weight Priority
1 50 5
2 30 8
3 90 6
4 20 7
5 80 9
After:
Box Weight Priority
3 90 6
5 80 9
1 50 5
2 30 8
4 20 7
We work in the int matrix:
data= new int[BoxNumber][3];
The sorting is based in the second column Weight. I am looking for a procedure that sorts the data array.
public void sortC(int[][] temp)
{
if (temp.length >= 2)
{
for (int i = 1; i <= temp.length - 1; i++)
{
int[] hold = temp[i];
int[] holdP = temp[i-1];
int j = i;
while (j > 0 && hold[1] < holdP[1]) // 1 represents the reference of sorting
{
hold = temp[j];
holdP = temp[j-1];
temp[j] = holdP;
temp[j-1] = hold;
j--;
}
}
}
}
sortC(data);
I tried this one, but unfortunately it doesn't give a right sorting I couldn't figure out the pickle.