public static void insertSort(int a[]) {
for(int i=1;i<a.length;i++) {
int j=i;
int temp=a[j];
while(j>0 && a[j-1]>temp) {
a[j]=a[j-1];
j--;
}
a[j]=temp;
}
一开始写的错误
public static void insertSort(int a[]) {
for(int i=1;i<a.length;i++) {
int j=i;
int temp=a[j];
while(j>0 && a[j-1]>a[j]) {
a[j]=a[j-1];
j--;
}
a[j]=temp;
}
看哪里有错误??
while 循环条件写错了 应该一直和temp比较的。