冒泡排序的程序出错,我排了一下午,汗
就是这个题了,我弄了一下午,一直没找到错在哪?无语public class TestDateSort {
public static void main(String[] args) {
Date[] days = new Date[5];
days[0] = new Date(2006, 1, 1);
days[1] = new Date(2006, 1, 2);
days[2] = new Date(2006, 1, 1);
days[3] = new Date(2010, 2, 3);
days[4] = new Date(2010, 2, 1);
bubbleSort(days);
for(int i = 0;i<days.length;i++)
System.out.println(days[i]);
}
public static Date[] bubbleSort(Date[] a) {
int t= a.length;
for(int i = t-1;i>=1;i--) {
for(int j = 0;j<i-1;j++) {
if(a[j].compare(a[j+1])>0) {
Date temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
return a;
}
}