【发布时间】:2015-04-07 05:31:09
【问题描述】:
按列对数组进行排序,就像我在这里想要做的是将我的值排序在我的最后一行,并且取决于对其他列上的数字排序可能在同一行中也发生变化
例如
int[][] array= { {1, 5, 3},{2, 6, 4},{12, 10, 1},{30, 75, 1} };
输出应该是
{12, 10, 1}
{30, 75, 1}
{1, 5, 3}
{2, 6, 4}
`System.out.println("Entre la cantidad de procesos que quiere correr:"); int 优点 = scan.nextInt();
int[][] myArr = new int[pros][3];
for(int i=0; i< pros; i++){
System.out.println("CPU Burst proceso "+count+" :");
time2=scan.nextInt();
System.out.println("Arrival Time proceso "+count+" :");
arrt=scan.nextInt();
myArr[i][0]=count;
myArr[i][1]=time2;
myArr[i][2]=arrt;
count++;
}
Arrays.sort(myArr, new Comparator<int[]>() {
public int compare(int[] o1, int[] o2) {
return Integer.compare(o2[2], o1[2]);
}
});
System.out.println(Arrays.deepToString(myArr)); `
【问题讨论】:
-
您能分享一下您到目前为止所尝试的内容吗?您至少需要半路来,以便我们为您提供帮助。
-
我找到了,但我尝试实现但没有工作 myArr.sort(function (a, b) { return a[2] - b[2]; });
-
您能帮我解决您想要的排序算法吗?根据您的输入和输出,我无法做出任何逻辑
-
对数组的最后一列进行排序,两列的值与排好序的列一致
标签: java arrays sorting compare