public static void sortIntArrs(int[][] a, String sortCols)
{
for (int i = 0; i < a.length; i++)
{
for (int j = i + 1; j < a.length; j++)
{
swap(a[i],a[j],sortCols);
}
}
} public static void swap(int m[], int n[], String sortCols)
{
int x;
boolean bSwap = false;
String y[] = sortCols.split(",");
for (int i = 0; i < y.length; i++)
{
int j = Integer.parseInt(y[i]);
if (j < m.length)
{
if (m[j] > n[j])
{
bSwap = true;
break;
}
else if(m[j]<n[j])
{
break;
}
}
}
if (bSwap)
{
for (int i = 0; i < m.length; i++)
{
x = m[i];
m[i] = n[i];
n[i] = x;
}
}
}
{
for (int i = 0; i < a.length; i++)
{
for (int j = i + 1; j < a.length; j++)
{
swap(a[i],a[j],sortCols);
}
}
} public static void swap(int m[], int n[], String sortCols)
{
int x;
boolean bSwap = false;
String y[] = sortCols.split(",");
for (int i = 0; i < y.length; i++)
{
int j = Integer.parseInt(y[i]);
if (j < m.length)
{
if (m[j] > n[j])
{
bSwap = true;
break;
}
else if(m[j]<n[j])
{
break;
}
}
}
if (bSwap)
{
for (int i = 0; i < m.length; i++)
{
x = m[i];
m[i] = n[i];
n[i] = x;
}
}
}
解决方案 »
- JUnit测试时为何会把数据插入到数据库
- 谁有ssh整合的例子呀。带jar包的,我用myeclipse添加jar包时老出错,感激不尽
- MyEclipse6.0把java程序打包的问
- hibernate 问题 onlyxu请进 求救
- JBoss的8080和Oracle的8080冲突怎么办
- 初学者:为什么Tomcat编译不了JSP?谢谢指教.
- 游戏服务器开发群.10585468
- 我用axis出了点问题,很简单,望赐教!
- RedHat9安装后,为什么最高分辨率才800*600?
- 工作流
- weblogic8+struts程序在hp-unix下能页面跳转,windows机上却dispathActionSupport error:null
- Freemarker有什么好处??
int[][] ids = { { 1, 2, 3, 4, 5 }, { 2, 3, 4, 5, 1 }, { 3, 4, 5, 1, 2 } };
List<int[]> list = new ArrayList<int[]>(); // 转化为List进行排序
for (int[] id : ids) {
list.add(id);
}
Collections.sort(list, new Comparator() {
public int compare(Object obj1, Object obj2) {
int[] id1 = (int[]) obj1;
int[] id2 = (int[]) obj2;
return id1[column] - id2[column];
}
});
for (int[] id : list) {
System.out.println(Arrays.toString(id));
}